]> git.saurik.com Git - apt.git/commitdiff
fix segfault with empty LongOpt in --no-* branch
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 9 Jun 2012 20:55:51 +0000 (22:55 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 9 Jun 2012 20:55:51 +0000 (22:55 +0200)
apt-pkg/contrib/cmndline.cc
debian/changelog
test/libapt/commandline_test.cc

index b8c7f79848de41d4f4779b216b326fe67bd610b3..75d02cad46972cc262906f7379185c5127f446e5 100644 (file)
@@ -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)
index 33b1732a651acaa3d68312eaa59c704d568eb117..b263002ae73a328b11f4b55f38a6446a91ff20f9 100644 (file)
@@ -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:
index a37fb022023392955a12d428e21c1fac98565498..de8a30bd6434cf82757e063f5d17423eca73033a 100644 (file)
@@ -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;
 }