From 5363fda9e7ebdc4dd191183ece2e6e070d68d716 Mon Sep 17 00:00:00 2001 From: Emanuele Rocca Date: Sat, 4 Oct 2008 22:13:00 +0200 Subject: Add tests/getcache_mem_corruption.py --- tests/getcache_mem_corruption.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/getcache_mem_corruption.py (limited to 'tests') diff --git a/tests/getcache_mem_corruption.py b/tests/getcache_mem_corruption.py new file mode 100644 index 00000000..e127f66e --- /dev/null +++ b/tests/getcache_mem_corruption.py @@ -0,0 +1,11 @@ +#!/usr/bin/python +import apt_pkg +import re + +apt_pkg.InitConfig() +apt_pkg.InitSystem() +apt_cache = apt_pkg.GetCache() +# wrong +apt_depcache = apt_pkg.GetCache(apt_cache) +# correct: apt_depcache = apt_pkg.GetDepCache(apt_cache) +re.compile('a') -- cgit v1.2.3 From 754744630ff6228029cd025074dc0cfe3de08495 Mon Sep 17 00:00:00 2001 From: Emanuele Rocca Date: Mon, 6 Oct 2008 10:31:30 +0200 Subject: Test case and proposed fix for Debian bug #497049 --- python/cache.cc | 17 ++++++++++++++--- tests/getcache_mem_corruption.py | 27 ++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/python/cache.cc b/python/cache.cc index bd280dec..523444b5 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -936,14 +936,25 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) pkgCacheFile *Cache = new pkgCacheFile(); if(pyCallbackInst != 0) { + if (PyObject_HasAttrString(pyCallbackInst, "done") != 1) { + PyErr_SetString(PyExc_ValueError, + "progress object must implement done()"); + return 0; + } + if (PyObject_HasAttrString(pyCallbackInst, "update") != 1) { + PyErr_SetString(PyExc_ValueError, + "progress 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 *CacheFileObj = diff --git a/tests/getcache_mem_corruption.py b/tests/getcache_mem_corruption.py index e127f66e..42e9af00 100644 --- a/tests/getcache_mem_corruption.py +++ b/tests/getcache_mem_corruption.py @@ -1,11 +1,24 @@ #!/usr/bin/python +import apt import apt_pkg import re -apt_pkg.InitConfig() -apt_pkg.InitSystem() -apt_cache = apt_pkg.GetCache() -# wrong -apt_depcache = apt_pkg.GetCache(apt_cache) -# correct: apt_depcache = apt_pkg.GetDepCache(apt_cache) -re.compile('a') +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() -- cgit v1.2.3