Skip to content

Commit ab68dad

Browse files
committed
in_kubernetes_events: reject signed uint64 strings in record_get_field_uint64
strtoull() itself accepts a leading '+'/'-' and skips leading whitespace, so a resourceVersion string like "-5" silently wrapped around into 18446744073709551611 instead of being rejected. Kubernetes always serializes resourceVersion as a plain unsigned digits-only decimal string, so require the first byte to be a digit before calling strtoull(), on top of the existing errno/ERANGE and full-consumption checks. Confirmed via a standalone guard-page harness (same shape as the existing OOB reproduction in this PR): "-5" and "+5" are now rejected (previously accepted, wrapping "-5" to UINT64_MAX-4), a valid digits-only value still round-trips correctly, and overflow beyond UINT64_MAX still correctly fails via the existing ERANGE check. Addresses a CodeRabbit review comment on this PR. Signed-off-by: Raphael Zanarelli <zanarelli.dev@gmail.com> Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
1 parent e3c31af commit ab68dad

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

plugins/in_kubernetes_events/kubernetes_events.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <sys/stat.h>
2323
#include <inttypes.h>
2424
#include <errno.h>
25+
#include <ctype.h>
2526

2627
#include <fluent-bit/flb_input_plugin.h>
2728
#include <fluent-bit/flb_network.h>
@@ -297,6 +298,18 @@ static int record_get_field_uint64(msgpack_object *obj, const char *fieldname, u
297298
memcpy(buf, v->via.str.ptr, len);
298299
buf[len] = '\0';
299300

301+
/*
302+
* strtoull() itself accepts a leading '+'/'-' and skips leading
303+
* whitespace, which would let a value like "-5" silently wrap
304+
* around into a huge positive number instead of being rejected.
305+
* Kubernetes resourceVersion (the only caller) is always a plain,
306+
* unsigned, digits-only decimal string, so require that directly
307+
* before parsing.
308+
*/
309+
if (!isdigit((unsigned char) buf[0])) {
310+
return -1;
311+
}
312+
300313
errno = 0;
301314
*val = strtoull(buf, &end, 10);
302315
if (errno == ERANGE || end == buf || *end != '\0') {

0 commit comments

Comments
 (0)