summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmanuele Rocca <ema@debian.org>2008-10-06 10:31:30 +0200
committerEmanuele Rocca <ema@debian.org>2008-10-06 10:31:30 +0200
commit754744630ff6228029cd025074dc0cfe3de08495 (patch)
treef97bb12295ac5b375f72b588f4b7f5eb42e7fee0
parent5363fda9e7ebdc4dd191183ece2e6e070d68d716 (diff)
downloadpython-apt-754744630ff6228029cd025074dc0cfe3de08495.tar.gz
Test case and proposed fix for Debian bug #497049
-rw-r--r--python/cache.cc17
-rw-r--r--tests/getcache_mem_corruption.py27
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()