From 7fb1deb23b411d2f4863a3eccaef6e28f3cbdb67 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 11 Apr 2022 11:11:58 +0800 Subject: [PATCH] Fix command line `--restart` option number conversion --- src/argparse.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/argparse.c b/src/argparse.c index 53a38937..26f10fa1 100644 --- a/src/argparse.c +++ b/src/argparse.c @@ -76,9 +76,12 @@ static inline size_t parse_restart_policy(const char *s, size_t *out) } else if (0 == strcmp(s, "on-failure")) { *out = NEU_RESTART_ONFAILURE; } else { - errno = 0; - uintmax_t n = strtoumax(s, NULL, 0); - if (0 != errno || n > NEU_RESTART_ALWAYS) { + errno = 0; + char * end = NULL; + uintmax_t n = strtoumax(s, &end, 0); + // the entire string should be a number within range + if (0 != errno || '\0' == *s || '\0' != *end || + n > NEU_RESTART_ALWAYS) { return -1; } *out = n;