diff --git a/src/common/impl/option.c b/src/common/impl/option.c index a6dc09673..7390f7b66 100644 --- a/src/common/impl/option.c +++ b/src/common/impl/option.c @@ -3,8 +3,12 @@ #include "common/color.h" #include "common/stringUtils.h" +#include + // Return start position of the inner key if the argument key belongs to the module specified, NULL otherwise const char* ffOptionTestPrefix(const char* argumentKey, const char* moduleName) { + assert(argumentKey && moduleName); + const char* subKey = argumentKey; if (!(subKey[0] == '-' && subKey[1] == '-')) { return NULL; @@ -47,13 +51,13 @@ uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value) { } char* end; - uint32_t num = (uint32_t) strtoul(value, &end, 10); - if (*end != '\0') { + unsigned long num = strtoul(value, &end, 10); + if (value[0] == '-' || *end != '\0' || num > UINT32_MAX) { fprintf(stderr, "Error: usage: %s \n", argumentKey); exit(479); } - return num; + return (uint32_t) num; } int32_t ffOptionParseInt32(const char* argumentKey, const char* value) { @@ -63,13 +67,13 @@ int32_t ffOptionParseInt32(const char* argumentKey, const char* value) { } char* end; - int32_t num = (int32_t) strtol(value, &end, 10); - if (*end != '\0') { + long num = strtol(value, &end, 10); + if (*end != '\0' || num < INT32_MIN || num > INT32_MAX) { fprintf(stderr, "Error: usage: %s \n", argumentKey); exit(479); } - return num; + return (int32_t) num; } int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]) {