From 1ce6e432b63d1706eda318170ea0d6ea094c2d6c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 3 Sep 2014 14:17:07 +0200 Subject: QVersionNumber: correctly fail for numerically very large segments The result of qstrtoull() was unconditionally truncated to an int, resulting in wrong values being appended to the segments vector when the numerical segment value was above INT_MAX. Prevent this by first checking the return value of qstrtoull as a qulonglong for values larger than INT_MAX and stopping processing in that case. That means that segments that numerically overflow an int are now considered part of the suffix. Also added tests for the case where a segment value is larger than ULLONG_MAX. That was already working correctly. Change-Id: Ia4b89021dcfe6bfae27c8d89bb678ec5e0e3b847 Reviewed-by: Thiago Macieira --- src/corelib/tools/qversionnumber.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools/qversionnumber.cpp') diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp index 933f7fa6b3..4d148249c0 100644 --- a/src/corelib/tools/qversionnumber.cpp +++ b/src/corelib/tools/qversionnumber.cpp @@ -54,6 +54,7 @@ #endif #include +#include QT_BEGIN_NAMESPACE @@ -390,14 +391,13 @@ QVersionNumber QVersionNumber::fromString(const QString &string, int *suffixInde const char *end = start; const char *lastGoodEnd = start; const char *endOfString = cString.constData() + cString.size(); - int value; do { bool ok = false; - value = int(qstrtoull(start, &end, 10, &ok)); - if (!ok) + const qulonglong value = qstrtoull(start, &end, 10, &ok); + if (!ok || value > qulonglong(std::numeric_limits::max())) break; - seg.append(value); + seg.append(int(value)); start = end + 1; lastGoodEnd = end; } while (start < endOfString && (end < endOfString && *end == '.')); -- cgit v1.2.3