MXS-1703 Better strtoll() & strtoull() error detection

The functions do not set errno on all invalid input, so it's best to check
endptr.

Also, strtoll is now used for server id scanning through QueryResult.
This commit is contained in:
Esa Korhonen
2018-04-11 17:58:43 +03:00
parent ca9682f042
commit 7f36339f53
4 changed files with 12 additions and 32 deletions

View File

@ -155,8 +155,9 @@ Gtid Gtid::from_string(const char* str, char** endptr)
{
errno = 0;
parsed_numbers[i] = strtoull(ptr, &strtoull_endptr, 10);
// No parse error
if (errno != 0)
// Check for parse error. Even this is not quite enough because strtoull will silently convert
// negative values. Yet, strtoull is required for the third value.
if (errno != 0 || strtoull_endptr == ptr)
{
error = true;
}