diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-18 14:26:58 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-24 10:06:53 +0100 |
commit | 6c435e5dd41177308f22ba4b55931b2c463cb0d8 (patch) | |
tree | cd607b37ec21b3c6bb2bfa5862c0e4bc2dc4d44b /src/corelib/io/qipaddress.cpp | |
parent | a036bd1746a8be9d8d9f15d70f8d0258d1a4fc46 (diff) |
Restore end-of-parse reporting to qstrntod()
Rework QSimpleParsedNumber to store a qsizetype whose sign serves as
ok flag (positive is ok, zero and negative are not) and magnitude is
the number of characters used. This replaces an endptr that was set to
null to indicate !ok, but that deprived us of end-of-parse
information, which is needed for number-parsing. In particular, JS's
parsing of numbers accepts overflow (where qstrntod() flags it as
invalid) as infinity; so qstrntod() does need to say how long the
overflowing (but JS-valid, none the less) number-text was.
Modify all callers of functions using this (recently-introduced) type
and add tests that fail without this fix.
Fixes: QTBUG-108628
Change-Id: I416cd213e1fb8101b1af5a6d43615b970a5db9b4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/io/qipaddress.cpp')
-rw-r--r-- | src/corelib/io/qipaddress.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp index feed38bef6..444a38a319 100644 --- a/src/corelib/io/qipaddress.cpp +++ b/src/corelib/io/qipaddress.cpp @@ -60,12 +60,12 @@ static bool parseIp4Internal(IPv4Address &address, const char *ptr, bool acceptL ptr[1] != '.' && ptr[1] != '\0') return false; - auto [ll, endptr] = qstrntoull(ptr, stop - ptr, 0); + auto [ll, used] = qstrntoull(ptr, stop - ptr, 0); quint32 x = ll; - if (!endptr || endptr == ptr || ll != x) + if (used <= 0 || ll != x) return false; - if (*endptr == '.' || dotCount == 3) { + if (ptr[used] == '.' || dotCount == 3) { if (x & ~0xff) return false; address <<= 8; @@ -80,13 +80,13 @@ static bool parseIp4Internal(IPv4Address &address, const char *ptr, bool acceptL } address |= x; - if (dotCount == 3 || *endptr == '\0') - return *endptr == '\0'; - if (*endptr != '.') + if (dotCount == 3 || ptr[used] == '\0') + return ptr[used] == '\0'; + if (ptr[used] != '.') return false; ++dotCount; - ptr = endptr + 1; + ptr += used + 1; } return false; } @@ -174,16 +174,16 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end continue; } - auto [ll, endptr] = qstrntoull(ptr, stop - ptr, 16); + auto [ll, used] = qstrntoull(ptr, stop - ptr, 16); quint16 x = ll; // Reject malformed fields: // - failed to parse // - too many hex digits - if (!endptr || endptr > ptr + 4) + if (used <= 0 || used > 4) return begin + (ptr - buffer.data()); - if (*endptr == '.') { + if (ptr[used] == '.') { // this could be an IPv4 address // it's only valid in the last element if (pos != 12) @@ -203,11 +203,11 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end address[pos++] = x >> 8; address[pos++] = x & 0xff; - if (*endptr == '\0') + if (ptr[used] == '\0') break; - if (*endptr != ':') - return begin + (endptr - buffer.data()); - ptr = endptr + 1; + if (ptr[used] != ':') + return begin + (used + ptr - buffer.data()); + ptr += used + 1; } return pos == 16 ? nullptr : end; } |