diff options
| author | Julian Andres Klode <jak@debian.org> | 2011-04-11 10:13:15 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2011-04-11 10:13:15 +0200 |
| commit | d5e763e1920eadf0bc0d460abbf686c65db2a3b4 (patch) | |
| tree | f0f38674b4281ac5502366b4a41563d1407085ee | |
| parent | fedfc6ec4584f43364e13e35326d051f5526700b (diff) | |
| download | python-apt-d5e763e1920eadf0bc0d460abbf686c65db2a3b4.tar.gz | |
apt_pkg: Raise error when parse_commandline gets empty argv (LP: #707416)
| -rw-r--r-- | debian/changelog | 1 | ||||
| -rw-r--r-- | python/configuration.cc | 4 | ||||
| -rw-r--r-- | tests/test_configuration.py | 30 |
3 files changed, 35 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog index 9d708753..e71cd63a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ python-apt (0.8.0~exp2) UNRELEASED; urgency=low * aptsources: Various cleanup work * all: Fix all instances of ResourceWarning about unclosed files * tests/test_apt_cache.py: Use assertTrue() instead of assert_() + * apt_pkg: Raise error when parse_commandline gets empty argv (LP: #707416) -- Julian Andres Klode <jak@debian.org> Wed, 06 Apr 2011 09:46:52 +0200 diff --git a/python/configuration.cc b/python/configuration.cc index 93e92efa..b6a44b44 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -438,6 +438,10 @@ PyObject *ParseCommandLine(PyObject *Self,PyObject *Args) return 0; } + if (PySequence_Length(Pargv) < 1) { + PyErr_SetString(PyExc_ValueError,"argv is an empty sequence"); + return 0; + } // Convert the option list int Length = PySequence_Length(POList); CommandLine::Args *OList = new CommandLine::Args[Length+1]; diff --git a/tests/test_configuration.py b/tests/test_configuration.py new file mode 100644 index 00000000..80509cff --- /dev/null +++ b/tests/test_configuration.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +# +# Copyright (C) 2011 Julian Andres Klode <jak@debian.org> +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. +"""Unit tests for verifying the correctness of apt_pkg.Configuration""" +import unittest + +import apt_pkg + + +class TestConfiguration(unittest.TestCase): + """Test various configuration things""" + + def setUp(self): + """Prepare the tests, create reference values...""" + apt_pkg.init_config() + + def test_lp707416(self): + """configuration: Test empty arguments (LP: #707416)""" + self.assertRaises(ValueError, apt_pkg.parse_commandline, + apt_pkg.config,[], []) + self.assertRaises(SystemError, apt_pkg.parse_commandline, + apt_pkg.config,[], ["cmd", "--arg0"]) + + +if __name__ == "__main__": + unittest.main() |
