]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_graylog2: additional input checks on LOG_FIELDS[]
authorChris Rienzo <chris.rienzo@grasshopper.com>
Fri, 11 Jul 2014 14:38:29 +0000 (10:38 -0400)
committerChris Rienzo <chris.rienzo@grasshopper.com>
Fri, 11 Jul 2014 14:38:29 +0000 (10:38 -0400)
src/mod/loggers/mod_graylog2/mod_graylog2.c

index 2fe5213914053786abcb62fa39566c7ec4364f27..a65ac0281a2bae6ff63406243a0337e28ba83666 100644 (file)
@@ -116,23 +116,25 @@ static char *to_gelf(const switch_log_node_t *node, switch_log_level_t log_level
        if (*full_message == '\n') {
                full_message++;
        }
-       
+
        /* parse list of fields, if any */
        if (strncmp(full_message, "LOG_FIELDS", 10) == 0) {
                if (switch_event_create_brackets(full_message+10, '[', ']', ',', &log_fields, &parsed_full_message, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
-                       
+
                        switch_event_header_t *hp;
                        for (hp = log_fields->headers; hp; hp = hp->next) {
-                               if (strncmp(hp->name, "@#", 2) == 0) {
-                               field_name = switch_mprintf("_%s", hp->name + 2);
-                                       cJSON_AddItemToObject(gelf, field_name, cJSON_CreateNumber(strtod(hp->value, NULL)));   
-                               } else {
-                                       field_name = switch_mprintf("_%s", hp->name);
-                                       cJSON_AddItemToObject(gelf, field_name, cJSON_CreateString(hp->value));
+                               if (!zstr(hp->name) && !zstr(hp->value)) {
+                                       if (strncmp(hp->name, "@#", 2) == 0) {
+                                               field_name = switch_mprintf("_%s", hp->name + 2);
+                                               cJSON_AddItemToObject(gelf, field_name, cJSON_CreateNumber(strtod(hp->value, NULL)));
+                                       } else {
+                                               field_name = switch_mprintf("_%s", hp->name);
+                                               cJSON_AddItemToObject(gelf, field_name, cJSON_CreateString(hp->value));
+                                       }
+                                       free(field_name);
                                }
-                               free(field_name);
                        }
-                       
+
                        switch_event_destroy(&log_fields);
                        full_message = parsed_full_message;
                }
@@ -149,9 +151,7 @@ static char *to_gelf(const switch_log_node_t *node, switch_log_level_t log_level
        gelf_text = cJSON_PrintUnformatted(gelf);
        cJSON_Delete(gelf);
        
-       if (parsed_full_message != NULL) {
-               free(parsed_full_message);
-       }
+       switch_safe_free(parsed_full_message);
        
        return gelf_text;
 }