Skip to content

Commit

Permalink
in_elasticsearch: fixed potential issue caused by ingored reallocation
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Alminana <[email protected]>
  • Loading branch information
leonardo-albertovich authored and edsiper committed Sep 5, 2024
1 parent 278bd07 commit 03df4ed
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions plugins/in_elasticsearch/in_elasticsearch_bulk_prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,13 @@ int in_elasticsearch_bulk_prot_handle(struct flb_in_elasticsearch *ctx,
}
error_str = strstr(bulk_statuses, "\"status\":40");
if (error_str){
flb_sds_cat(bulk_response, "{\"errors\":true,\"items\":[", 24);
flb_sds_cat_safe(&bulk_response, "{\"errors\":true,\"items\":[", 24);
}
else {
flb_sds_cat(bulk_response, "{\"errors\":false,\"items\":[", 25);
flb_sds_cat_safe(&bulk_response, "{\"errors\":false,\"items\":[", 25);
}
flb_sds_cat(bulk_response, bulk_statuses, flb_sds_len(bulk_statuses));
flb_sds_cat(bulk_response, "]}", 2);
flb_sds_cat_safe(&bulk_response, bulk_statuses, flb_sds_len(bulk_statuses));
flb_sds_cat_safe(&bulk_response, "]}", 2);
send_response(conn, 200, bulk_response);

mk_mem_free(uri);
Expand All @@ -925,8 +925,8 @@ int in_elasticsearch_bulk_prot_handle_error(struct flb_in_elasticsearch *ctx,


/* New gen HTTP server */
static int send_response_ng(struct flb_http_response *response,
int http_status,
static int send_response_ng(struct flb_http_response *response,
int http_status,
char *content_type,
char *message)
{
Expand All @@ -946,14 +946,14 @@ static int send_response_ng(struct flb_http_response *response,
}

if (content_type != NULL) {
flb_http_response_set_header(response,
flb_http_response_set_header(response,
"content-type", 0,
content_type, 0);
}

if (message != NULL) {
flb_http_response_set_body(response,
(unsigned char *) message,
flb_http_response_set_body(response,
(unsigned char *) message,
strlen(message));
}

Expand All @@ -962,14 +962,14 @@ static int send_response_ng(struct flb_http_response *response,
return 0;
}

static int send_json_response_ng(struct flb_http_response *response,
static int send_json_response_ng(struct flb_http_response *response,
int http_status,
char *message)
{
return send_response_ng(response, http_status, "application/json", message);
return send_response_ng(response, http_status, "application/json", message);
}

static int send_version_message_response_ng(struct flb_http_response *response,
static int send_version_message_response_ng(struct flb_http_response *response,
struct flb_in_elasticsearch *ctx,
int http_status)
{
Expand All @@ -989,14 +989,14 @@ static int send_version_message_response_ng(struct flb_http_response *response,
ES_VERSION_RESPONSE_TEMPLATE,
ctx->es_version);

send_json_response_ng(response, http_status, message);
send_json_response_ng(response, http_status, message);

cfl_sds_destroy(message);

return 0;
}

static int send_dummy_sniffer_response_ng(struct flb_http_response *response,
static int send_dummy_sniffer_response_ng(struct flb_http_response *response,
struct flb_in_elasticsearch *ctx,
int http_status)
{
Expand Down Expand Up @@ -1024,7 +1024,7 @@ static int send_dummy_sniffer_response_ng(struct flb_http_response *response,
ctx->cluster_name, ctx->node_name,
hostname, ctx->tcp_port, ctx->buffer_max_size);

send_json_response_ng(response, http_status, resp);
send_json_response_ng(response, http_status, resp);

flb_sds_destroy(resp);

Expand Down Expand Up @@ -1081,7 +1081,7 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,
}

/* HTTP/1.1 needs Host header */
if (request->protocol_version == HTTP_PROTOCOL_HTTP1 &&
if (request->protocol_version == HTTP_PROTOCOL_HTTP1 &&
request->host == NULL) {

return -1;
Expand Down Expand Up @@ -1113,7 +1113,7 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,
else if (request->method == HTTP_METHOD_POST) {
if (strcmp(request->path, "/_bulk") == 0) {
bulk_statuses = flb_sds_create_size(context->buffer_max_size);

if (bulk_statuses == NULL) {
return -1;
}
Expand Down Expand Up @@ -1159,7 +1159,7 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,

flb_sds_destroy(bulk_statuses);
flb_sds_destroy(bulk_response);

} else {
send_response_ng(response, 400, NULL, "error: invalid HTTP endpoint\n");

Expand All @@ -1171,6 +1171,6 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,

return -1;
}

return 0;
}

0 comments on commit 03df4ed

Please sign in to comment.