From 4b1d284bb57219b6677a8bda5cdc14a24a6aa22d Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 30 Oct 2025 11:43:27 +0100 Subject: [PATCH] output/http: log content-type like other headers Ticket: 8056 Avoid stack allocation. Do not handle null and ; especially (cherry picked from commit b8411fcc8dfc16910c3080d4d8c03a9a64c3a1f7) --- src/output-json-http.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/output-json-http.c b/src/output-json-http.c index bd3f6a1166..87191caa9c 100644 --- a/src/output-json-http.c +++ b/src/output-json-http.c @@ -237,13 +237,12 @@ static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx) if (tx->response_headers != NULL) { htp_header_t *h_content_type = htp_table_get_c(tx->response_headers, "content-type"); if (h_content_type != NULL) { - const size_t size = bstr_len(h_content_type->value) * 2 + 1; - char string[size]; - BytesToStringBuffer(bstr_ptr(h_content_type->value), bstr_len(h_content_type->value), string, size); - char *p = strchr(string, ';'); + uint32_t len = (uint32_t)bstr_len(h_content_type->value); + const uint8_t *p = memchr(bstr_ptr(h_content_type->value), ';', len); if (p != NULL) - *p = '\0'; - jb_set_string(js, "http_content_type", string); + len = (uint32_t)(p - bstr_ptr(h_content_type->value)); + jb_set_string_from_bytes( + js, "http_content_type", bstr_ptr(h_content_type->value), len); } htp_header_t *h_content_range = htp_table_get_c(tx->response_headers, "content-range"); if (h_content_range != NULL) {