summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2012-06-09 22:55:51 +0200
committerDavid Kalnischkies <kalnischkies@gmail.com>2012-06-09 22:55:51 +0200
commit7a6d9076595b2acc164d6f057f609c96c359ea08 (patch)
treef3fdc21c3e5891cad360220c136d714b1af0b88f
parentae2be086c6996e6ed02b7d828fdcac38248a964d (diff)
fix segfault with empty LongOpt in --no-* branch
-rw-r--r--apt-pkg/contrib/cmndline.cc3
-rw-r--r--debian/changelog1
-rw-r--r--test/libapt/commandline_test.cc15
3 files changed, 16 insertions, 3 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index b8c7f7984..75d02cad4 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -106,7 +106,8 @@ bool CommandLine::Parse(int argc,const char **argv)
Opt++;
for (A = ArgList; A->end() == false &&
- stringcasecmp(Opt,OptEnd,A->LongOpt) != 0; A++);
+ (A->LongOpt == 0 || stringcasecmp(Opt,OptEnd,A->LongOpt) != 0);
+ ++A);
// Failed again..
if (A->end() == true && OptEnd - Opt != 1)
diff --git a/debian/changelog b/debian/changelog
index 33b1732a6..b263002ae 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -22,6 +22,7 @@ apt (0.9.5.2) UNRELEASED; urgency=low
* apt-pkg/contrib/cmdline.cc:
- apply patch from Daniel Hartwig to fix a segfault in case
the LongOpt is empty (Closes: #676331)
+ - fix segfault with empty LongOpt in --no-* branch
[ Justin B Rye ]
* doc/apt-cdrom.8.xml:
diff --git a/test/libapt/commandline_test.cc b/test/libapt/commandline_test.cc
index a37fb0220..de8a30bd6 100644
--- a/test/libapt/commandline_test.cc
+++ b/test/libapt/commandline_test.cc
@@ -9,13 +9,24 @@ int main()
{ 'z', "zero", "Test::Zero", 0 },
{0,0,0,0}
};
-
CommandLine CmdL(Args,_config);
+
char const * argv[] = { "test", "--zero", "-t" };
CmdL.Parse(3 , argv);
-
equals(true, _config->FindB("Test::Worked", false));
equals(true, _config->FindB("Test::Zero", false));
+ _config->Clear("Test");
+ equals(false, _config->FindB("Test::Worked", false));
+ equals(false, _config->FindB("Test::Zero", false));
+
+ _config->Set("Test::Zero", true);
+ equals(true, _config->FindB("Test::Zero", false));
+
+ char const * argv2[] = { "test", "--no-zero", "-t" };
+ CmdL.Parse(3 , argv2);
+ equals(true, _config->FindB("Test::Worked", false));
+ equals(false, _config->FindB("Test::Zero", false));
+
return 0;
}