Skip to content

Commit 5161df1

Browse files
committed
pipeline: outputs: es: avoid zero pointer dereferencing when HTTP client creation failed
Signed-off-by: Marat Abrarov <[email protected]>
1 parent fe9944a commit 5161df1

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

plugins/out_es/es.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -836,15 +836,15 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
836836
{
837837
int ret;
838838
size_t pack_size;
839-
char *pack;
840-
void *out_buf;
839+
char *pack = NULL;
840+
void *out_buf = NULL;
841841
size_t out_size;
842842
size_t b_sent;
843843
struct flb_elasticsearch *ctx = out_context;
844844
struct flb_elasticsearch_config *ec;
845845
struct flb_connection *u_conn;
846846
struct flb_upstream_node *node;
847-
struct flb_http_client *c;
847+
struct flb_http_client *c = NULL;
848848
flb_sds_t signature = NULL;
849849
int compressed = FLB_FALSE;
850850
flb_sds_t header_line = NULL;
@@ -912,6 +912,11 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
912912
/* Compose HTTP Client request */
913913
c = flb_http_client(u_conn, FLB_HTTP_POST, ec->uri,
914914
pack, pack_size, NULL, 0, NULL, 0);
915+
if (!c) {
916+
flb_plg_error(ctx->ins, "failed to create HTTP client");
917+
ret = FLB_ERROR;
918+
goto cleanup_and_return;
919+
}
915920

916921
flb_http_buffer_size(c, ec->buffer_size);
917922

@@ -1029,29 +1034,24 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
10291034
}
10301035
}
10311036

1037+
ret = FLB_OK;
1038+
1039+
cleanup_and_return:
10321040
/* Cleanup */
1033-
flb_http_client_destroy(c);
1041+
if (c) {
1042+
flb_http_client_destroy(c);
1043+
}
10341044
flb_free(pack);
10351045
flb_upstream_conn_release(u_conn);
10361046
if (signature) {
10371047
flb_sds_destroy(signature);
10381048
}
1039-
FLB_OUTPUT_RETURN(FLB_OK);
1049+
FLB_OUTPUT_RETURN(ret);
10401050

10411051
/* Issue a retry */
10421052
retry:
1043-
flb_http_client_destroy(c);
1044-
flb_free(pack);
1045-
1046-
if (out_buf != pack) {
1047-
flb_free(out_buf);
1048-
}
1049-
1050-
flb_upstream_conn_release(u_conn);
1051-
if (signature) {
1052-
flb_sds_destroy(signature);
1053-
}
1054-
FLB_OUTPUT_RETURN(FLB_RETRY);
1053+
ret = FLB_RETRY;
1054+
goto cleanup_and_return;
10551055
}
10561056

10571057
static int elasticsearch_response_test(struct flb_config *config,
@@ -1080,6 +1080,10 @@ static int elasticsearch_response_test(struct flb_config *config,
10801080
/* Compose HTTP Client request (dummy client) */
10811081
c = flb_http_dummy_client(u_conn, FLB_HTTP_POST, ec->uri,
10821082
NULL, 0, NULL, 0, NULL, 0);
1083+
if (!c) {
1084+
flb_plg_error(ctx->ins, "failed to create dummy HTTP client");
1085+
return -2;
1086+
}
10831087

10841088
flb_http_buffer_size(c, ec->buffer_size);
10851089

0 commit comments

Comments
 (0)