diff options
| -rw-r--r-- | python/cache.cc | 17 | ||||
| -rw-r--r-- | tests/getcache_mem_corruption.py | 27 |
2 files changed, 34 insertions, 10 deletions
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<pkgCacheFile*> *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() |
