Commit 3c20b3fc authored by dejun.xdj's avatar dejun.xdj
Browse files

Bugfix: xadd command ID parse

strictly check the string to be converted,
strtoull() in libc may not set errno to EINVAL when the string contains
invalid digits.
parent 8ac7af1c
...@@ -917,8 +917,10 @@ int string2ull(const char *s, unsigned long long *value) { ...@@ -917,8 +917,10 @@ int string2ull(const char *s, unsigned long long *value) {
return 1; return 1;
} }
errno = 0; errno = 0;
*value = strtoull(s,NULL,10); char *endptr = NULL;
if (errno == EINVAL || errno == ERANGE) return 0; /* strtoull() failed. */ *value = strtoull(s,&endptr,10);
if (errno == EINVAL || errno == ERANGE || !(*s != '\0' && *endptr == '\0'))
return 0; /* strtoull() failed. */
return 1; /* Conversion done! */ return 1; /* Conversion done! */
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment