[sr-dev] [kamailio/kamailio] kazoo application may send zero string to kamailio this trigers crash (#2794)

sergey-safarov notifications at github.com
Fri Jul 2 00:48:50 CEST 2021


I have reproduced the issue by calling `kz_json_parse(mystr)` where `mysrt` has `NULL` value.
```diff
diff --git a/src/modules/kazoo/kz_amqp.c b/src/modules/kazoo/kz_amqp.c
index 8076315dfd..6f5f84716a 100644
--- a/src/modules/kazoo/kz_amqp.c
+++ b/src/modules/kazoo/kz_amqp.c
@@ -2417,6 +2417,7 @@ static void kz_amqp_consumer_event_kemi(void)
 
 void kz_amqp_consumer_event(kz_amqp_consumer_delivery_ptr Evt)
 {
+       char* mystr = NULL;
        json_obj_ptr json_obj = NULL;
 
        eventData = Evt->payload;
@@ -2424,6 +2425,7 @@ void kz_amqp_consumer_event(kz_amqp_consumer_delivery_ptr Evt)
                eventKey = Evt->routing_key->s;
        }
 
+       json_obj = kz_json_parse(mystr);
        json_obj = kz_json_parse(Evt->payload);
        if (json_obj == NULL)
                return;
```

I have fixed issue by:
```diff
diff --git a/src/modules/kazoo/kz_json.c b/src/modules/kazoo/kz_json.c
index 5ab8f68c79..0e5f2e8b10 100644
--- a/src/modules/kazoo/kz_json.c
+++ b/src/modules/kazoo/kz_json.c
@@ -276,6 +276,11 @@ struct json_object* kz_json_parse(const char *str)
     struct json_tokener* tok;
     struct json_object* obj;
 
+    if (str == NULL || str[0] == 0) {
+      LM_ERR("Error parsing json: empty string\n");
+      return NULL;
+    }
+
     tok = json_tokener_new();
     if (!tok) {
       LM_ERR("Error parsing json: could not allocate tokener\n");
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2794#issuecomment-872595128
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20210701/8bc1bf19/attachment.htm>


More information about the sr-dev mailing list