diff --git a/src/output-json-file.c b/src/output-json-file.c index d86f2cbd3e..c2c6464819 100644 --- a/src/output-json-file.c +++ b/src/output-json-file.c @@ -81,11 +81,11 @@ static json_t *LogFileMetaGetUri(const Packet *p, const File *ff) { if (tx != NULL) { HtpTxUserData *tx_ud = htp_tx_get_user_data(tx); if (tx_ud->request_uri_normalized != NULL) { - char *s = SCStrndup((char *) bstr_ptr(tx_ud->request_uri_normalized), - bstr_len(tx_ud->request_uri_normalized)); - js = json_string(s); - if (s != NULL) + char *s = bstr_util_strdup_to_c(tx_ud->request_uri_normalized); + if (s != NULL) { + js = json_string(s); SCFree(s); + } } return js; } @@ -100,11 +100,11 @@ static json_t *LogFileMetaGetHost(const Packet *p, const File *ff) { if (htp_state != NULL) { htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, htp_state, ff->txid); if (tx != NULL && tx->request_hostname != NULL) { - char *s = SCStrndup((char *) bstr_ptr(tx->request_hostname), - bstr_len(tx->request_hostname)); - js = json_string(s); - if (s != NULL) + char *s = bstr_util_strdup_to_c(tx->request_hostname); + if (s != NULL) { + js = json_string(s); SCFree(s); + } return js; } } @@ -122,11 +122,11 @@ static json_t *LogFileMetaGetReferer(const Packet *p, const File *ff) { h = (htp_header_t *)htp_table_get_c(tx->request_headers, "Referer"); if (h != NULL) { - char *s = SCStrndup((char *)bstr_ptr(h->value), - bstr_len(h->value)); - js = json_string(s); - if (s != NULL) + char *s = bstr_util_strdup_to_c(h->value); + if (s != NULL) { + js = json_string(s); SCFree(s); + } return js; } } @@ -145,11 +145,11 @@ static json_t *LogFileMetaGetUserAgent(const Packet *p, const File *ff) { h = (htp_header_t *)htp_table_get_c(tx->request_headers, "User-Agent"); if (h != NULL) { - char *s = SCStrndup((char *)bstr_ptr(h->value), - bstr_len(h->value)); - js = json_string(s); - if (s != NULL) + char *s = bstr_util_strdup_to_c(h->value); + if (s != NULL) { + js = json_string(s); SCFree(s); + } return js; } } diff --git a/src/output-json-http.c b/src/output-json-http.c index 703f11692e..0a968485e8 100644 --- a/src/output-json-http.c +++ b/src/output-json-http.c @@ -83,8 +83,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) /* hostname */ if (tx->request_hostname != NULL) { - c = SCStrndup((char *)bstr_ptr(tx->request_hostname), - bstr_len(tx->request_hostname)); + c = bstr_util_strdup_to_c(tx->request_hostname); if (c != NULL) { json_object_set_new(hjs, "hostname", json_string(c)); SCFree(c); @@ -96,8 +95,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) /* uri */ if (tx->request_uri != NULL) { - c = SCStrndup((char *)bstr_ptr(tx->request_uri), - bstr_len(tx->request_uri)); + c = bstr_util_strdup_to_c(tx->request_uri); if (c != NULL) { json_object_set_new(hjs, "url", json_string(c)); SCFree(c); @@ -110,8 +108,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) h_user_agent = htp_table_get_c(tx->request_headers, "user-agent"); } if (h_user_agent != NULL) { - c = SCStrndup((char *)bstr_ptr(h_user_agent->value), - bstr_len(h_user_agent->value)); + c = bstr_util_strdup_to_c(h_user_agent->value); if (c != NULL) { json_object_set_new(hjs, "http_user_agent", json_string(c)); SCFree(c); @@ -126,8 +123,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) h_x_forwarded_for = htp_table_get_c(tx->request_headers, "x-forwarded-for"); } if (h_x_forwarded_for != NULL) { - c = SCStrndup((char *)bstr_ptr(h_x_forwarded_for->value), - bstr_len(h_x_forwarded_for->value)); + c = bstr_util_strdup_to_c(h_x_forwarded_for->value); if (c != NULL) { json_object_set_new(hjs, "xff", json_string(c)); SCFree(c); @@ -141,8 +137,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) } if (h_content_type != NULL) { char *p; - c = SCStrndup((char *)bstr_ptr(h_content_type->value), - bstr_len(h_content_type->value)); + c = bstr_util_strdup_to_c(h_content_type->value); if (c != NULL) { p = strchrnul(c, ';'); *p = '\0'; @@ -158,8 +153,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) h_referer = htp_table_get_c(tx->request_headers, "referer"); } if (h_referer != NULL) { - c = SCStrndup((char *)bstr_ptr(h_referer->value), - bstr_len(h_referer->value)); + c = bstr_util_strdup_to_c(h_referer->value); if (c != NULL) { json_object_set_new(hjs, "http_refer", json_string(c)); SCFree(c); @@ -168,8 +162,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) /* method */ if (tx->request_method != NULL) { - c = SCStrndup((char *)bstr_ptr(tx->request_method), - bstr_len(tx->request_method)); + c = bstr_util_strdup_to_c(tx->request_method); if (c != NULL) { json_object_set_new(hjs, "http_method", json_string(c)); SCFree(c); @@ -178,8 +171,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) /* protocol */ if (tx->request_protocol != NULL) { - c = SCStrndup((char *)bstr_ptr(tx->request_protocol), - bstr_len(tx->request_protocol)); + c = bstr_util_strdup_to_c(tx->request_protocol); if (c != NULL) { json_object_set_new(hjs, "protocol", json_string(c)); SCFree(c); @@ -188,8 +180,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) /* response status */ if (tx->response_status != NULL) { - c = SCStrndup((char *)bstr_ptr(tx->response_status), - bstr_len(tx->response_status)); + c = bstr_util_strdup_to_c(tx->response_status); if (c != NULL) { json_object_set_new(hjs, "status", json_string(c)); SCFree(c); @@ -197,8 +188,7 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx) htp_header_t *h_location = htp_table_get_c(tx->response_headers, "location"); if (h_location != NULL) { - c = SCStrndup((char *)bstr_ptr(h_location->value), - bstr_len(h_location->value)); + c = bstr_util_strdup_to_c(h_location->value); if (c != NULL) { json_object_set_new(hjs, "redirect", json_string(c)); SCFree(c);