From 27425e62c071441fa8ef34775b6ad7d985e07fde Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 18 May 2016 08:50:53 +0200 Subject: Moc: fix crash when a file ends with \\\r MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit make the 'cleaned' more robust by making sure we do not read past the buffer in some cases. We must also use resize and not reserve on the outpt buffer because reseve is meant as a hint and we are not supposed to write past the size of the QByteArray even if it is reserved. [ChangeLog][moc] Fixed crash on file ending with \\\r Task-number: QTBUG-53441 Change-Id: I901e6c0ffc7f8877de3d07fd08cf26495461d294 Reviewed-by: Jędrzej Nowacki Reviewed-by: Robert Loehning --- src/tools/moc/preprocessor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index a2a1a958cf..bfe61d0895 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE static QByteArray cleaned(const QByteArray &input) { QByteArray result; - result.reserve(input.size()); + result.resize(input.size()); const char *data = input.constData(); const char *end = input.constData() + input.size(); char *output = result.data(); @@ -78,13 +78,15 @@ static QByteArray cleaned(const QByteArray &input) if (data != end && (*(data + 1) == '\n' || (*data) == '\r')) { ++newlines; data += 1; - if (*data != '\r') + if (data != end && *data != '\r') data += 1; continue; } } else if (*data == '\r' && *(data + 1) == '\n') { // reduce \r\n to \n ++data; } + if (data == end) + break; char ch = *data; if (ch == '\r') // os9: replace \r with \n -- cgit v1.2.3