Skip to content

Commit

Permalink
fix out-of-bounds access on trailing percent sign in tr() argument
Browse files Browse the repository at this point in the history
tr() recognizes %n and %Ln. it offers no way to escape lone percent
signs, which implies that they must be interpreted verbatim, which is
what the code actually does. except that it would run off the end if the
% appeared at the end of the string.

Fixes: QTBUG-57171
Done-with: Mateusz Starzycki <mstarzycki@gmail.com>
Change-Id: Icf81925c482be1ea66ec8daafb3e92ad17ea7fab
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
  • Loading branch information
ossilator committed Jan 14, 2019
1 parent 6178913 commit c365fa4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/corelib/kernel/qcoreapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,9 +2097,13 @@ static void replacePercentN(QString *result, int n)
int len = 0;
while ((percentPos = result->indexOf(QLatin1Char('%'), percentPos + len)) != -1) {
len = 1;
if (percentPos + len == result->length())
break;
QString fmt;
if (result->at(percentPos + len) == QLatin1Char('L')) {
++len;
if (percentPos + len == result->length())
break;
fmt = QLatin1String("%L1");
} else {
fmt = QLatin1String("%1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,12 @@ void tst_QCoreApplication::threadedEventDelivery()
thread.start();
QVERIFY(thread.wait(1000));
QCOMPARE(receiver.recordedEvents.contains(QEvent::User + 1), eventsReceived);

}

void tst_QCoreApplication::testTrWithPercantegeAtTheEnd()
{
QCoreApplication::translate("testcontext", "this will crash%", "testdisamb", 3);
}

#if QT_CONFIG(library)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private slots:
void applicationEventFilters_auxThread();
void threadedEventDelivery_data();
void threadedEventDelivery();
void testTrWithPercantegeAtTheEnd();
#if QT_CONFIG(library)
void addRemoveLibPaths();
#endif
Expand Down

0 comments on commit c365fa4

Please sign in to comment.