Reproduction test case for a crash described in Bug 330066

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
Lukasz Kotula 6 years ago committed by Kurt Hindenburg
parent b5d02842fc
commit 37ffb50e59
  1. 3
      src/Screen.h
  2. 6
      src/autotests/CMakeLists.txt
  3. 72
      src/autotests/ScreenTest.cpp
  4. 50
      src/autotests/ScreenTest.h

@ -32,6 +32,7 @@
// Konsole
#include "Character.h"
#include "konsoleprivate_export.h"
#define MODE_Origin 0
#define MODE_Wrap 1
@ -70,7 +71,7 @@ class HistoryScroll;
using selectedText(). When getImage() is used to retrieve the visible image,
characters which are part of the selection have their colors inverted.
*/
class Screen
class KONSOLEPRIVATE_EXPORT Screen
{
public:
/* PlainText: Return plain text (default)

@ -87,6 +87,12 @@ ecm_mark_nongui_executable(ShellCommandTest)
add_test(ShellCommandTest ShellCommandTest)
target_link_libraries(ShellCommandTest ${KONSOLE_TEST_LIBS})
add_executable(ScreenTest ScreenTest.cpp)
ecm_mark_as_test(ScreenTest)
ecm_mark_nongui_executable(ScreenTest)
add_test(ScreenTest ScreenTest)
target_link_libraries(ScreenTest ${KONSOLE_TEST_LIBS})
add_executable(TerminalCharacterDecoderTest
TerminalCharacterDecoderTest.cpp)
ecm_mark_as_test(TerminalCharacterDecoderTest)

@ -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…
Cancel
Save