summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/cmndline.cc5
-rw-r--r--debian/changelog3
-rw-r--r--test/libapt/commandline_test.cc21
-rw-r--r--test/libapt/makefile6
4 files changed, 33 insertions, 2 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index 159f330a1..b8c7f7984 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -92,8 +92,9 @@ bool CommandLine::Parse(int argc,const char **argv)
// Match up to a = against the list
Args *A;
const char *OptEnd = strchrnul(Opt, '=');
- for (A = ArgList; A->end() == false &&
- stringcasecmp(Opt,OptEnd,A->LongOpt) != 0; A++);
+ for (A = ArgList; A->end() == false &&
+ (A->LongOpt == 0 || stringcasecmp(Opt,OptEnd,A->LongOpt) != 0);
+ ++A);
// Failed, look for a word after the first - (no-foo)
bool PreceedMatch = false;
diff --git a/debian/changelog b/debian/changelog
index 9a135db01..33b1732a6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -19,6 +19,9 @@ apt (0.9.5.2) UNRELEASED; urgency=low
as we do in the manpage and as the debian-installer does
* doc/apt-get.8.xml:
- use apt-utils as package example instead of libc6
+ * apt-pkg/contrib/cmdline.cc:
+ - apply patch from Daniel Hartwig to fix a segfault in case
+ the LongOpt is empty (Closes: #676331)
[ Justin B Rye ]
* doc/apt-cdrom.8.xml:
diff --git a/test/libapt/commandline_test.cc b/test/libapt/commandline_test.cc
new file mode 100644
index 000000000..a37fb0220
--- /dev/null
+++ b/test/libapt/commandline_test.cc
@@ -0,0 +1,21 @@
+#include <apt-pkg/cmndline.h>
+
+#include "assert.h"
+
+int main()
+{
+ CommandLine::Args Args[] = {
+ { 't', 0, "Test::Worked", 0 },
+ { '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));
+
+ return 0;
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
index 1952051e2..b2e6db2dd 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -34,6 +34,12 @@ SOURCE = getlistoffilesindir_test.cc
include $(PROGRAM_H)
# Program for testing CommandLine reconstruction
+PROGRAM = Commandline${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = commandline_test.cc
+include $(PROGRAM_H)
+
+# Program for testing CommandLine reconstruction
PROGRAM = CommandlineAsString${BASENAME}
SLIBS = -lapt-pkg
SOURCE = commandlineasstring_test.cc