瀏覽代碼

fix segfault with empty LongOpt in --no-* branch

David Kalnischkies 14 年之前
父節點
當前提交
7a6d907659
共有 3 個文件被更改,包括 16 次插入3 次删除
  1. 2 1
      apt-pkg/contrib/cmndline.cc
  2. 1 0
      debian/changelog
  3. 13 2
      test/libapt/commandline_test.cc

+ 2 - 1
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)

+ 1 - 0
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:

+ 13 - 2
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;
 }