Don't accept trailing characters when validating numbers for --format

strtoull succeed when the leading characters of the input form a valid
number, so it is necessary to verify that there is no trailing
characters. Use the endptr parameter (that will point to the end of
the accepted input) to verify that.

Fixes #142.

Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
This commit is contained in:
Caio Marcelo de Oliveira Filho
2017-08-22 11:00:26 -07:00
committed by Matthew Johnson
parent 49ec50f3da
commit 4a6796c47f
+3 -2
View File
@@ -301,10 +301,11 @@ int set_version_url(char *url)
static bool is_valid_integer_format(char *str)
{
unsigned long long int version;
char *endptr = NULL;
errno = 0;
version = strtoull(str, NULL, 10);
if ((errno < 0) || (version == 0)) {
version = strtoull(str, &endptr, 10);
if ((errno < 0) || (version == 0) || (endptr && *endptr != '\0')) {
return false;
}