eBPF-based security platform
status, upatch: parse numeric options in decimal only
Daniel Borkmannd80302ce400a
diff --git a/builtin-status.c b/builtin-status.cindex 5ddee0df..8ca9de45 100644--- a/builtin-status.c+++ b/builtin-status.c@@ -23,6 +23,7 @@#include <bpf/libbpf.h>#include <shirudo/misc.h>+#include <shirudo/string.h>#include <shirudo/upatch.h>#include <time.h>@@ -561,12 +562,11 @@ int cmd_status(int argc, const char **argv)} else if (strcmp(argv[i], "--include-kernellog") == 0) {include_kernel_log = true;} else if (strncmp(argv[i], "--include-kernellog=", 20) == 0) {- char *end;+ const char *n = argv[i] + 20;__u64 v;- v = strtoul(argv[i] + 20, &end, 0);- if (*end != '\0' || v < 1 ||- v > SHIRUDO_KERNEL_LOG_MAX) {+ if (parse_u64(n, strlen(n), SHIRUDO_KERNEL_LOG_MAX, &v) ||+ v < 1) {fprintf(stderr, "status: --include-kernellog=N ""must be 1..%d\n",SHIRUDO_KERNEL_LOG_MAX);diff --git a/builtin-upatch.c b/builtin-upatch.cindex 05bba3c2..01542e88 100644--- a/builtin-upatch.c+++ b/builtin-upatch.c@@ -32,6 +32,7 @@#include <bpf/libbpf.h>#include <shirudo/misc.h>+#include <shirudo/string.h>#include "builtin.h"#include "util/chain.h"@@ -2969,7 +2970,6 @@ static int cmd_upatch_map(int argc, const char **argv)insecure_set = true;otel_opts.allow_insecure = true;} else if (strncmp(a, "--otel-retries=", 15) == 0) {- char *end;__u64 value;if (retries_set || !a[15]) {@@ -2977,9 +2977,7 @@ static int cmd_upatch_map(int argc, const char **argv)"--otel-retries\n");return 2;}- errno = 0;- value = strtoul(a + 15, &end, 10);- if (errno || *end || value > 10) {+ if (parse_u64(a + 15, strlen(a + 15), 10, &value)) {fprintf(stderr, "upatch map: --otel-retries must be 0..10\n");return 2;}