[PATCH 3 of 6 cpychecker] pathencode: check result of .digest() method in sha1hash

Augie Fackler raf at durin42.com
Tue Aug 18 16:54:13 CDT 2015


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1439929961 14400
#      Tue Aug 18 16:32:41 2015 -0400
# Node ID ec2dee7d4778fc4bc46dff6a74e5af26a99cadb5
# Parent  f47c42732b0a684119f99fde44f372ffe7380dcb
pathencode: check result of .digest() method in sha1hash

Without this it was theoretically possible .digest() would fail and
return NULL but we wouldn't notice. Detected with cpychecker.

diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -684,6 +684,8 @@ static int sha1hash(char hash[20], const
 
 	hashobj = PyObject_CallMethod(shaobj, "digest", "");
 	Py_DECREF(shaobj);
+	if (hashobj == NULL)
+		return -1;
 
 	if (!PyString_Check(hashobj) || PyString_GET_SIZE(hashobj) != 20) {
 		PyErr_SetString(PyExc_TypeError,


More information about the Mercurial-devel mailing list