New unit test, triggers faulty code in `Screen::copyLineToStream` which goes outside `Character` array boundaries, overwriting memory of other objects. Compiling the code with address-sanitizer makes the fault visible when running those new UTs.wilder-portage
parent
b5d02842fc
commit
37ffb50e59
4 changed files with 130 additions and 1 deletions
@ -0,0 +1,72 @@ |
||||
/*
|
||||
Copyright 2020 by Lukasz Kotula <lukasz.kotula@gmx.com> |
||||
|
||||
This program is free software; you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation; either version 2 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
||||
02110-1301 USA. |
||||
*/ |
||||
|
||||
// Own
|
||||
#include "ScreenTest.h" |
||||
|
||||
// Qt
|
||||
#include <QString> |
||||
|
||||
// KDE
|
||||
#include <qtest.h> |
||||
|
||||
using namespace Konsole; |
||||
|
||||
void ScreenTest::doLargeScreenCopyVerification(const QString &putToScreen, const QString &expectedSelection) |
||||
{ |
||||
Screen screen(largeScreenLines, largeScreenColumns); |
||||
|
||||
for(const auto lineCharacter : putToScreen) { |
||||
screen.displayCharacter(lineCharacter.toLatin1()); |
||||
} |
||||
|
||||
screen.setSelectionStart(0,0, false); |
||||
screen.setSelectionEnd(largeScreenColumns,0); |
||||
QCOMPARE(screen.selectedText(Screen::PlainText), expectedSelection); |
||||
} |
||||
|
||||
void ScreenTest::testLargeScreenCopyShortLine() |
||||
{ |
||||
const QString putToScreen = QStringLiteral("0123456789abcde"); |
||||
const QString expectedSelection = QStringLiteral("0123456789abcde\n"); |
||||
doLargeScreenCopyVerification(putToScreen, expectedSelection); |
||||
} |
||||
|
||||
void ScreenTest::testLargeScreenCopyEmptyLine() |
||||
{ |
||||
const QString putToScreen; |
||||
const QString expectedSelection = QStringLiteral("\n"); |
||||
|
||||
doLargeScreenCopyVerification(putToScreen, expectedSelection); |
||||
} |
||||
|
||||
void ScreenTest::testLargeScreenCopyLongLine() |
||||
{ |
||||
QString putToScreen; |
||||
|
||||
// Make the line longer than screen size (1300 characters)
|
||||
for(int i = 0; i <130; ++i) { |
||||
putToScreen.append(QStringLiteral("0123456789")); |
||||
} |
||||
const QString expectedSelection = putToScreen.left(1200); |
||||
|
||||
doLargeScreenCopyVerification(putToScreen, expectedSelection); |
||||
} |
||||
|
||||
QTEST_GUILESS_MAIN(ScreenTest) |
||||
@ -0,0 +1,50 @@ |
||||
/*
|
||||
Copyright 2020 by Lukasz Kotula <lukasz.kotula@gmx.com> |
||||
|
||||
This program is free software; you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation; either version 2 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
||||
02110-1301 USA. |
||||
*/ |
||||
|
||||
|
||||
#ifndef SHELLCOMMANDTEST_H |
||||
#define SHELLCOMMANDTEST_H |
||||
|
||||
#include <QObject> |
||||
|
||||
#include "../Screen.h" |
||||
|
||||
namespace Konsole |
||||
{ |
||||
|
||||
class ScreenTest : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
private Q_SLOTS: |
||||
void testLargeScreenCopyShortLine(); |
||||
void testLargeScreenCopyEmptyLine(); |
||||
void testLargeScreenCopyLongLine(); |
||||
|
||||
private: |
||||
void doLargeScreenCopyVerification(const QString &putToScreen, const QString &expectedSelection); |
||||
|
||||
const int largeScreenLines = 10; |
||||
const int largeScreenColumns = 1200; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif // SHELLCOMMANDTEST_H
|
||||
|
||||
Loading…
Reference in new issue