From ccf689a426760a69b77394abbcddf7897cbd6488 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 4 Jul 2008 19:53:47 +0200 Subject: * python/apt_pkgmodule.cc: - fix bug in hashsum calculation when the original string contains \0 charackters (thanks to Celso Providelo and Ryan Hass for the test-case) LP: #243630 --- python/apt_pkgmodule.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index ae1cf7be..dea34958 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -175,8 +175,11 @@ static PyObject *md5sum(PyObject *Self,PyObject *Args) // Digest of a string. if (PyString_Check(Obj) != 0) { + char *s; + Py_ssize_t len; MD5Summation Sum; - Sum.Add(PyString_AsString(Obj)); + PyString_AsStringAndSize(Obj, &s, &len); + Sum.Add((const unsigned char*)s, len); return CppPyString(Sum.Result().Value()); } @@ -212,8 +215,10 @@ static PyObject *sha1sum(PyObject *Self,PyObject *Args) // Digest of a string. if (PyString_Check(Obj) != 0) { + char *s; + Py_ssize_t len; SHA1Summation Sum; - Sum.Add(PyString_AsString(Obj)); + Sum.Add((const unsigned char*)s, len); return CppPyString(Sum.Result().Value()); } @@ -249,8 +254,11 @@ static PyObject *sha256sum(PyObject *Self,PyObject *Args) // Digest of a string. if (PyString_Check(Obj) != 0) { + char *s; + Py_ssize_t len; SHA256Summation Sum; - Sum.Add(PyString_AsString(Obj)); + PyString_AsStringAndSize(Obj, &s, &len); + Sum.Add((const unsigned char*)s, len); return CppPyString(Sum.Result().Value()); } -- cgit v1.2.3