smtp json: fix potential crash on malloc failure

** CID 1298888:    (FORWARD_NULL)
/src/output-json-email-common.c: 117 in JsonEmailLogJson()
/src/output-json-email-common.c: 140 in JsonEmailLogJson()
pull/1564/merge
Victor Julien 11 years ago
parent 1ed8d7b538
commit bd73553027

@ -114,19 +114,21 @@ static TmEcode JsonEmailLogJson(JsonEmailLogThread *aft, json_t *js, const Packe
if (field != NULL) { if (field != NULL) {
json_t *js_to = json_array(); json_t *js_to = json_array();
if (likely(js_to != NULL)) { if (likely(js_to != NULL)) {
char *savep = NULL;
char *p;
to_line = BytesToString((uint8_t *)field->value, to_line = BytesToString((uint8_t *)field->value,
(size_t)field->value_len); (size_t)field->value_len);
//printf("to_line:: TO: \"%s\" (%d)\n", to_line, strlen(to_line)); if (likely(to_line != NULL)) {
p = strtok_r(to_line, ",", &savep); char *savep = NULL;
//printf("got another addr: \"%s\"\n", p); char *p;
json_array_append_new(js_to, json_string(p)); //printf("to_line:: TO: \"%s\" (%d)\n", to_line, strlen(to_line));
while ((p = strtok_r(NULL, ",", &savep)) != NULL) { p = strtok_r(to_line, ",", &savep);
//printf("got another addr: \"%s\"\n", p); //printf("got another addr: \"%s\"\n", p);
json_array_append_new(js_to, json_string(&p[strspn(p, " ")])); json_array_append_new(js_to, json_string(p));
while ((p = strtok_r(NULL, ",", &savep)) != NULL) {
//printf("got another addr: \"%s\"\n", p);
json_array_append_new(js_to, json_string(&p[strspn(p, " ")]));
}
SCFree(to_line);
} }
SCFree(to_line);
json_object_set_new(sjs, "to", js_to); json_object_set_new(sjs, "to", js_to);
} }
} }
@ -137,19 +139,21 @@ static TmEcode JsonEmailLogJson(JsonEmailLogThread *aft, json_t *js, const Packe
if (field != NULL) { if (field != NULL) {
json_t *js_cc = json_array(); json_t *js_cc = json_array();
if (likely(js_cc != NULL)) { if (likely(js_cc != NULL)) {
char *savep = NULL;
char *p;
cc_line = BytesToString((uint8_t *)field->value, cc_line = BytesToString((uint8_t *)field->value,
(size_t)field->value_len); (size_t)field->value_len);
//printf("cc_line:: CC: \"%s\" (%d)\n", to_line, strlen(to_line)); if (likely(cc_line != NULL)) {
p = strtok_r(cc_line, ",", &savep); char *savep = NULL;
//printf("got another addr: \"%s\"\n", p); char *p;
json_array_append_new(js_cc, json_string(p)); //printf("cc_line:: CC: \"%s\" (%d)\n", to_line, strlen(to_line));
while ((p = strtok_r(NULL, ",", &savep)) != NULL) { p = strtok_r(cc_line, ",", &savep);
//printf("got another addr: \"%s\"\n", p); //printf("got another addr: \"%s\"\n", p);
json_array_append_new(js_cc, json_string(&p[strspn(p, " ")])); json_array_append_new(js_cc, json_string(p));
while ((p = strtok_r(NULL, ",", &savep)) != NULL) {
//printf("got another addr: \"%s\"\n", p);
json_array_append_new(js_cc, json_string(&p[strspn(p, " ")]));
}
SCFree(cc_line);
} }
SCFree(cc_line);
json_object_set_new(sjs, "cc", js_cc); json_object_set_new(sjs, "cc", js_cc);
} }
} }

Loading…
Cancel
Save