Skip to content

Commit a1d9c2a

Browse files
committed
in_forward: fix init error cleanup and parser state handling
- Reset per-message option state in forward parser to avoid stale options reuse. - Fix HELO handshake path to return error immediately on send failure. - Add NULL-check for security.users split parsing. - Use fw_config_destroy() on init failures to cleanly release allocated resources. - Align options index types/sentinels (chunk_id/metadata_id) to int for safer comparisons. Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 3b64243 commit a1d9c2a

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

plugins/in_forward/fw.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ static int setup_users(struct flb_in_fw_config *ctx,
222222

223223
/* As a value we expect a pair of a username and a passowrd */
224224
split = flb_utils_split(kv->val, ' ', 1);
225+
if (split == NULL) {
226+
flb_plg_error(ctx->ins,
227+
"invalid value, expected username and password");
228+
delete_users(ctx);
229+
flb_free(user);
230+
return -1;
231+
}
232+
225233
if (mk_list_size(split) != 2) {
226234
flb_plg_error(ctx->ins,
227235
"invalid value, expected username and password");
@@ -348,7 +356,7 @@ static int in_fw_init(struct flb_input_instance *ins,
348356
/* Load users */
349357
ret = setup_users(ctx, ins);
350358
if (ret == -1) {
351-
flb_free(ctx);
359+
fw_config_destroy(ctx);
352360
return -1;
353361
}
354362

plugins/in_forward/fw_config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins)
9090
ret = flb_input_config_map_set(i_ins, (void *)config);
9191
if (ret == -1) {
9292
flb_plg_error(i_ins, "config map set error");
93-
flb_free(config);
93+
fw_config_destroy(config);
9494
return NULL;
9595
}
9696

@@ -117,6 +117,7 @@ struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins)
117117
/* Shared Key */
118118
if (config->empty_shared_key) {
119119
if (fw_create_empty_shared_key(config, i_ins) == -1) {
120+
fw_config_destroy(config);
120121
return NULL;
121122
}
122123
}

plugins/in_forward/fw_prot.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ int flb_secure_forward_set_helo(struct flb_input_instance *in,
254254
static int send_helo(struct flb_input_instance *in, struct flb_connection *connection,
255255
struct flb_in_fw_helo *helo)
256256
{
257-
int result;
258257
size_t sent;
259258
ssize_t bytes;
260259
msgpack_packer mp_pck;
@@ -302,16 +301,10 @@ static int send_helo(struct flb_input_instance *in, struct flb_connection *conne
302301

303302
if (bytes == -1) {
304303
flb_plg_error(in, "cannot send HELO");
305-
306-
result = -1;
307-
}
308-
else {
309-
result = 0;
304+
return -1;
310305
}
311306

312-
result = flb_secure_forward_set_helo(in, helo, nonce, user_auth_salt);
313-
314-
return result;
307+
return flb_secure_forward_set_helo(in, helo, nonce, user_auth_salt);
315308
}
316309

317310
static void flb_secure_forward_format_bin_to_hex(uint8_t *buf, size_t len, char *out)
@@ -827,7 +820,7 @@ static int send_ack(struct flb_input_instance *in, struct fw_conn *conn,
827820

828821
}
829822

830-
static size_t get_options_metadata(msgpack_object *arr, int expected, size_t *idx)
823+
static int get_options_metadata(msgpack_object *arr, int expected, int *idx)
831824
{
832825
size_t i;
833826
msgpack_object *options;
@@ -880,15 +873,15 @@ static size_t get_options_metadata(msgpack_object *arr, int expected, size_t *id
880873
return -1;
881874
}
882875

883-
*idx = i;
876+
*idx = (int) i;
884877

885878
return 0;
886879
}
887880

888881
return 0;
889882
}
890883

891-
static size_t get_options_chunk(msgpack_object *arr, int expected, size_t *idx)
884+
static int get_options_chunk(msgpack_object *arr, int expected, int *idx)
892885
{
893886
size_t i;
894887
msgpack_object *options;
@@ -941,7 +934,7 @@ static size_t get_options_chunk(msgpack_object *arr, int expected, size_t *idx)
941934
return -1;
942935
}
943936

944-
*idx = i;
937+
*idx = (int) i;
945938
return 0;
946939
}
947940

@@ -1256,9 +1249,9 @@ int fw_prot_process(struct flb_input_instance *ins, struct fw_conn *conn)
12561249
int stag_len;
12571250
int event_type;
12581251
int contain_options = FLB_FALSE;
1252+
int chunk_id = -1;
1253+
int metadata_id = -1;
12591254
size_t index = 0;
1260-
size_t chunk_id = -1;
1261-
size_t metadata_id = -1;
12621255
const char *stag;
12631256
flb_sds_t out_tag = NULL;
12641257
size_t bytes;
@@ -1353,6 +1346,7 @@ int fw_prot_process(struct flb_input_instance *ins, struct fw_conn *conn)
13531346

13541347
/* Map the array */
13551348
root = result.data;
1349+
contain_options = FLB_FALSE;
13561350

13571351
if (root.type != MSGPACK_OBJECT_ARRAY) {
13581352
flb_plg_debug(ctx->ins,

0 commit comments

Comments
 (0)