From d9779e3ff14a0139fcd7f9ad212d71ee967e9305 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Wed, 3 Aug 2016 17:40:50 -0700 Subject: [PATCH] option-parser: Improve error checking for strtol call Make the error checking consistent with other strtol() calls. Note that since strtol(nptr, &endptr) sets endptr == nptr if there were no digits, this catches the case where the string was blank, so there's no need to test *value != '\0'. Signed-off-by: Bryce Harrington Reviewed-by: Eric Engestrom Reviewed-by: Peter Hutterer --- shared/option-parser.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shared/option-parser.c b/shared/option-parser.c index 33355b8b..fb4a3424 100644 --- a/shared/option-parser.c +++ b/shared/option-parser.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "config-parser.h" @@ -40,11 +41,17 @@ handle_option(const struct weston_option *option, char *value) switch (option->type) { case WESTON_OPTION_INTEGER: + errno = 0; * (int32_t *) option->data = strtol(value, &p, 10); - return *value && !*p; + if (errno != 0 || p == value || *p != '\0') + return 0; + return 1; case WESTON_OPTION_UNSIGNED_INTEGER: + errno = 0; * (uint32_t *) option->data = strtoul(value, &p, 10); - return *value && !*p; + if (errno != 0 || p == value || *p != '\0') + return 0; + return 1; case WESTON_OPTION_STRING: * (char **) option->data = strdup(value); return 1;