From: Victor Julien Date: Wed, 12 Dec 2018 18:57:14 +0000 (+0100) Subject: eve/ftp: don't alloc memory to log filename X-Git-Tag: suricata-5.0.0-beta1~201 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e1235c9c8c983800aac020b123b0229f91662e1;p=thirdparty%2Fsuricata.git eve/ftp: don't alloc memory to log filename --- diff --git a/src/app-layer-ftp.c b/src/app-layer-ftp.c index d3931a863d..c36f561a77 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -61,6 +61,8 @@ #include "rust-ftp-mod-gen.h" #endif +#include "output-json.h" + uint64_t ftp_config_memcap = 0; SC_ATOMIC_DECLARE(uint64_t, ftp_memuse); @@ -995,10 +997,10 @@ json_t *JsonFTPDataAddMetadata(const Flow *f) if (ftpd == NULL) return NULL; if (ftp_state->file_name) { - char *s = BytesToString(ftp_state->file_name, ftp_state->file_len); - json_object_set_new(ftpd, "filename", json_string(s)); - if (s != NULL) - SCFree(s); + size_t size = ftp_state->file_len * 2 + 1; + char string[size]; + BytesToStringBuffer(ftp_state->file_name, ftp_state->file_len, string, size); + json_object_set_new(ftpd, "filename", SCJsonString(string)); } switch (ftp_state->command) { case FTP_COMMAND_STOR: