From: Victor Julien Date: Mon, 31 Oct 2016 10:14:41 +0000 (+0100) Subject: eve: make payload printing in alerts more robust X-Git-Tag: suricata-3.2RC1~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0f25bddaf3a5b05d8fc963b37472878eeeb175f;p=thirdparty%2Fsuricata.git eve: make payload printing in alerts more robust --- diff --git a/src/output-json-alert.c b/src/output-json-alert.c index 6d921dd05d..4fc6cb5a29 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -368,8 +368,9 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p) if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) { unsigned long len = p->payload_len * 2 + 1; uint8_t encoded[len]; - Base64Encode(p->payload, p->payload_len, encoded, &len); - json_object_set_new(js, "payload", json_string((char *)encoded)); + if (Base64Encode(p->payload, p->payload_len, encoded, &len) == SC_BASE64_OK) { + json_object_set_new(js, "payload", json_string((char *)encoded)); + } } if (json_output_ctx->flags & LOG_JSON_PAYLOAD) { @@ -378,6 +379,7 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p) PrintStringsToBuffer(printable_buf, &offset, p->payload_len + 1, p->payload, p->payload_len); + printable_buf[p->payload_len] = '\0'; json_object_set_new(js, "payload_printable", json_string((char *)printable_buf)); } }