From ae2be086c6996e6ed02b7d828fdcac38248a964d Mon Sep 17 00:00:00 2001 From: Daniel Hartwig Date: Sat, 9 Jun 2012 22:49:37 +0200 Subject: * apt-pkg/contrib/cmdline.cc: - apply patch from Daniel Hartwig to fix a segfault in case the LongOpt is empty (Closes: #676331) --- test/libapt/commandline_test.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/libapt/commandline_test.cc (limited to 'test/libapt/commandline_test.cc') 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 + +#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; +} -- cgit v1.2.3 From 7a6d9076595b2acc164d6f057f609c96c359ea08 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 9 Jun 2012 22:55:51 +0200 Subject: fix segfault with empty LongOpt in --no-* branch --- test/libapt/commandline_test.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'test/libapt/commandline_test.cc') 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; } -- cgit v1.2.3