]> git.saurik.com Git - apt.git/commitdiff
* apt-pkg/contrib/cmdline.cc:
authorDaniel Hartwig <mandyke@gmail.com>
Sat, 9 Jun 2012 20:49:37 +0000 (22:49 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 9 Jun 2012 20:49:37 +0000 (22:49 +0200)
  - apply patch from Daniel Hartwig to fix a segfault in case
    the LongOpt is empty (Closes: #676331)

apt-pkg/contrib/cmndline.cc
debian/changelog
test/libapt/commandline_test.cc [new file with mode: 0644]
test/libapt/makefile

index 159f330a182488d35cf9a930f265e5def324a82e..b8c7f79848de41d4f4779b216b326fe67bd610b3 100644 (file)
@@ -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;
index 9a135db015cf1db05f9d99cbcdd834a4a4ca8da5..33b1732a651acaa3d68312eaa59c704d568eb117 100644 (file)
@@ -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 (file)
index 0000000..a37fb02
--- /dev/null
@@ -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;
+}
index 1952051e28008e23a2bb552ed781f0923b1c2efb..b2e6db2dd0dd1a76b2046a6b2517f0fa513d00d3 100644 (file)
@@ -33,6 +33,12 @@ SLIBS = -lapt-pkg
 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