Commit 5baccc9b authored by Harald Sitter's avatar Harald Sitter
Browse files

Prevent crashes on source entries that contain a line like "##"

Simply ensure that while we are stripping # the string retains the
QString::at(i) requirement of i being a valid index (which requires the
size() to be greater than 0 for us).

Random note: while size>0 is equal to !isEmpty, the ::at() documentation
specifically ties the validity of index to size, so for clarity's sake I am
using size>0 rather than !isEmpty.

FIXED-IN: 2.2.1
BUG: 333675
parent a8f0e7b5
......@@ -87,7 +87,7 @@ void SourceEntryPrivate::parseData(const QString &data)
isEnabled = false;
}
// Handle multiple comment characters (hey, it happens!)
while (tData.at(0) == '#') {
while (tData.size() > 0 && tData.at(0) == '#') {
// Remove starting '#' from tData
tData = tData.remove(0, 1);
tData = tData.trimmed();
......
......@@ -10,3 +10,4 @@ deb [arch=i386,ppc] https://apttest/ubuntu saucy contrib main partner
# deb [arch=i386,ppc] http://apttest/ubuntu saucy contrib main partner
#deb [arch=i386,ppc] http://apttest/ubuntu saucy contrib main partner
###deb [arch=i386,ppc] http://apttest/ubuntu saucy contrib main partner
##
......@@ -249,8 +249,8 @@ void SourcesListTest::testConstructor()
* 2. Verify that we loaded the file using entries()
* 3. Verify that we loaded the file using entries(filename)
*/
#define SOURCES_COUNT 12
#define TEST1_MD5 "327eec1a9e826859e478258e75c07fbb"
#define SOURCES_COUNT 13
#define TEST1_MD5 "56717306e28a529f89b56c6ee6082375"
void SourcesListTest::testLoadSourcesOneFile()
{
QVERIFY2(sampleSourcesHasOneFile.count() == 1, "Verify we have only one source...");
......@@ -429,6 +429,19 @@ void SourcesListTest::testLoadSourcesOneFile()
false, // <-- Note, disabled!
true
);
// This line ensures that lines only containing comment characters (e.g. ##)
// are discarded as invalid.
verifySourceEntry(
"Line #12",
entries[12],
"",
"",
"",
"",
"",
false, // <-- Note, disabled!
false
);
}
#define SOURCES_COUNT_2 3
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment