Skip to content

Commit d5fa098

Browse files
committed
in_systemd: improve error handling
This patch addresses three issues: - Add NULL check after flb_strndup to prevent potential segfault when memory allocation fails - Add type validation for msgpack object before accessing map fields to prevent undefined behavior with non-map data - Fix FLUENT_BIT_PARSER counting toward max_fields limit by returning -1 instead of 0 Signed-off-by: Nour Douffir <[email protected]>
1 parent 53d645e commit d5fa098

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

plugins/in_systemd/systemd.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ static int flb_systemd_repack_map(struct flb_log_event_encoder *encoder,
9696
&offset);
9797

9898
if (result == MSGPACK_UNPACK_SUCCESS) {
99-
result = FLB_EVENT_ENCODER_SUCCESS;
99+
if (source_map.data.type == MSGPACK_OBJECT_MAP) {
100+
result = FLB_EVENT_ENCODER_SUCCESS;
101+
}
102+
else {
103+
result = FLB_EVENT_DECODER_ERROR_DESERIALIZATION_FAILURE;
104+
}
100105
}
101106
else {
102107
result = FLB_EVENT_DECODER_ERROR_DESERIALIZATION_FAILURE;
@@ -215,9 +220,10 @@ static int systemd_enumerate_data_store(struct flb_config *config,
215220
len = (sep - key);
216221
key_len = len;
217222

218-
/* Skip FLUENT_BIT_PARSER field - it's metadata, not log content */
223+
/* Skip FLUENT_BIT_PARSER field - it's metadata, not log content
224+
* Return -1 so it doesn't count toward max_fields */
219225
if (strncmp(key, "FLUENT_BIT_PARSER", key_len) == 0) {
220-
return 0;
226+
return -1;
221227
}
222228

223229
/* If this is MESSAGE field and parser is specified, apply parser */
@@ -423,11 +429,16 @@ static int in_systemd_collect(struct flb_input_instance *ins,
423429
ret = sd_journal_get_data(ctx->j, "FLUENT_BIT_PARSER", &data, &length);
424430
if (ret == 0) {
425431
name = flb_strndup((const char *)(data+18), length-18);
426-
parser = flb_parser_get(name, config);
427-
if (!parser) {
428-
flb_plg_error(ctx->ins, "no such parser: '%s'", name);
432+
if (name == NULL) {
433+
flb_plg_error(ctx->ins, "failed to allocate parser name");
434+
}
435+
else {
436+
parser = flb_parser_get(name, config);
437+
if (!parser) {
438+
flb_plg_error(ctx->ins, "no such parser: '%s'", name);
439+
}
440+
flb_free(name);
429441
}
430-
flb_free(name);
431442
}
432443

433444
if (last_tag_len == 0) {

0 commit comments

Comments
 (0)