diff options
| -rw-r--r-- | debian/changelog | 4 | ||||
| -rw-r--r-- | po/python-apt.pot | 2 | ||||
| -rw-r--r-- | python/cache.cc | 18 | ||||
| -rw-r--r-- | tests/getcache_mem_corruption.py | 24 |
4 files changed, 44 insertions, 4 deletions
diff --git a/debian/changelog b/debian/changelog index f8494712..9df26b05 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,10 @@ python-apt (0.7.9~exp3) experimental; urgency=low config from it as well * python/configuration.cc, python/apt_pkgmodule.cc: - add apt_pkg.ReadConfigDir() + * python/cache.cc, tests/getcache_mem_corruption.py: + - test if progress objects have the right methods + and raise error if not (thanks to Emanuele Rocca) + closes: #497049 * apt/package.py: - avoid uneeded interal references in the Package objects diff --git a/po/python-apt.pot b/po/python-apt.pot index 9bcda683..217c772c 100644 --- a/po/python-apt.pot +++ b/po/python-apt.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-01-29 09:24+0100\n" +"POT-Creation-Date: 2009-03-03 21:17+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" diff --git a/python/cache.cc b/python/cache.cc index 1c59bece..0c59f561 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -936,14 +936,26 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) pkgCacheFile *Cache = new pkgCacheFile(); if(pyCallbackInst != 0) { + // sanity check for the progress object, see #497049 + if (PyObject_HasAttrString(pyCallbackInst, "done") != true) { + PyErr_SetString(PyExc_ValueError, + "OpProgress object must implement done()"); + return 0; + } + if (PyObject_HasAttrString(pyCallbackInst, "update") != true) { + PyErr_SetString(PyExc_ValueError, + "OpProgress object must implement update()"); + return 0; + } PyOpProgress progress; progress.setCallbackInst(pyCallbackInst); if (Cache->Open(progress,false) == false) - return HandleErrors(); - } else { + return HandleErrors(); + } + else { OpTextProgress Prog; if (Cache->Open(Prog,false) == false) - return HandleErrors(); + return HandleErrors(); } CppOwnedPyObject<pkgCacheFile*> *CacheFileObj = diff --git a/tests/getcache_mem_corruption.py b/tests/getcache_mem_corruption.py new file mode 100644 index 00000000..42e9af00 --- /dev/null +++ b/tests/getcache_mem_corruption.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +import apt +import apt_pkg +import re + +import unittest + +class TestGetCache(unittest.TestCase): + + def setUp(self): + apt_pkg.InitConfig() + apt_pkg.InitSystem() + + def testWrongInvocation(self): + # wrongly invoke GetCache() rather than GetDepCache() + apt_cache = apt_pkg.GetCache() + self.assertRaises(ValueError, apt_pkg.GetCache, apt_cache) + + def testProperInvocation(self): + apt_cache = apt_pkg.GetCache(apt.progress.OpTextProgress()) + apt_depcache = apt_pkg.GetDepCache(apt_cache) + +if __name__ == "__main__": + unittest.main() |
