eBPF-based security platform
upatch_decode: parse the decoders' u64 strings with parse_u64()
Daniel Borkmannd8933af0a2a1
diff --git a/Makefile.shirudo b/Makefile.shirudoindex 5b8d8e9c..3d0806e8 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -672,7 +672,8 @@ testing/helper/test-upatch-serializer-pages: testing/helper/test-upatch-serializ$(Q)$(CC) $(CFLAGS) -o $@ $^ $(STATIC_LIBS) $(DYNAMIC_LIBS)testing/helper/test-upatch-decode: testing/helper/test-upatch-decode.c \- util/upatch_decode.o util/upatch.o util/malloc.o util/hex.o+ util/upatch_decode.o util/upatch.o util/malloc.o util/hex.o \+ util/string.o@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ $(DYNAMIC_LIBS)diff --git a/util/upatch_decode.c b/util/upatch_decode.cindex 17fdc3a9..247d426c 100644--- a/util/upatch_decode.c+++ b/util/upatch_decode.c@@ -9,6 +9,7 @@#include <errno.h>#include <shirudo/misc.h>+#include <shirudo/string.h>#include "upatch_decode.h"@@ -819,24 +820,14 @@ static int lua_shirudo_page_slots(lua_State *L)static int lua_check_u64_string(lua_State *L, int arg, __u64 *out){- const char *s = luaL_checkstring(L, arg);- __u64 v = 0;- size_t i;+ size_t len;+ const char *s = luaL_checklstring(L, arg, &len);+ int rc = parse_u64(s, len, UINT64_MAX, out);- if (!s[0] || strlen(s) > 20)+ if (rc == -ERANGE)+ return luaL_argerror(L, arg, "u64 string out of range");+ if (rc)return luaL_argerror(L, arg, "expected a decimal u64 string");- for (i = 0; s[i]; i++) {- __u32 digit;-- if (s[i] < '0' || s[i] > '9')- return luaL_argerror(L, arg,- "expected a decimal u64 string");- digit = (__u32)(s[i] - '0');- if (v > (UINT64_MAX - digit) / 10)- return luaL_argerror(L, arg, "u64 string out of range");- v = v * 10 + digit;- }- *out = v;return 0;}