From f5715d478aceb09c9eaa302500ff48bc046de415 Mon Sep 17 00:00:00 2001 From: Mohd Husaam Mehdi Date: Tue, 19 Aug 2025 17:14:44 +0530 Subject: [PATCH] fluent-bit: fix kmsg plugin issues * improved type conversion * improved error checking while string parsing * misc improvements --- fluent-bit/patches/0020-fix_kmsg.patch | 73 ++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 fluent-bit/patches/0020-fix_kmsg.patch diff --git a/fluent-bit/patches/0020-fix_kmsg.patch b/fluent-bit/patches/0020-fix_kmsg.patch new file mode 100644 index 000000000..14b2774c8 --- /dev/null +++ b/fluent-bit/patches/0020-fix_kmsg.patch @@ -0,0 +1,73 @@ +diff --git a/plugins/in_kmsg/in_kmsg.c b/plugins/in_kmsg/in_kmsg.c +index cd5c4cd17..15f105451 100644 +--- a/plugins/in_kmsg/in_kmsg.c ++++ b/plugins/in_kmsg/in_kmsg.c +@@ -36,7 +36,6 @@ + #include + #include + #include +-#include + + #include "in_kmsg.h" + +@@ -123,12 +122,17 @@ static inline int process_line(const char *line, + ctx->buffer_id++; + + errno = 0; +- val = strtol(p, &end, 10); +- if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN)) ++ val = strtoul(p, &end, 10); ++ if ((errno == ERANGE && val == ULONG_MAX) + || (errno != 0 && val == 0)) { + goto fail; + } + ++ /* ensure something was consumed */ ++ if (end == p) { ++ goto fail; ++ } ++ + /* Priority */ + priority = FLB_KLOG_PRI(val); + +@@ -144,24 +148,35 @@ static inline int process_line(const char *line, + } + p++; + +- val = strtoul(p, &end, 10); +- if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN)) ++ val = strtoull(p, &end, 10); ++ if ((errno == ERANGE && val == ULLONG_MAX) + || (errno != 0 && val == 0)) { + goto fail; + } + ++ /* make sure strtoull consumed something */ ++ /* after the sequence number, the next char must be ',' */ ++ if (end == p || *end != ',') { ++ goto fail; ++ } ++ + sequence = val; + p = ++end; + + /* Timestamp */ +- val = strtoul(p, &end, 10); +- if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN)) ++ val = strtoull(p, &end, 10); ++ if ((errno == ERANGE && val == ULLONG_MAX) + || (errno != 0 && val == 0)) { + goto fail; + } + ++ /* ensure something was consumed */ ++ if (end == p) { ++ goto fail; ++ } ++ + tv.tv_sec = val/1000000; +- tv.tv_usec = val - (tv.tv_sec * 1000000); ++ tv.tv_usec = val - ((uint64_t)tv.tv_sec * 1000000); + + flb_time_set(&ts, ctx->boot_time.tv_sec + tv.tv_sec, tv.tv_usec * 1000); +