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

login
register
mail settings
Submitter Augie Fackler
Date Aug. 18, 2015, 9:54 p.m.
Message ID <ec2dee7d4778fc4bc46d.1439934853@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/10236/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 18, 2015, 9:54 p.m.
# HG changeset patch
# User Augie Fackler <augie@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.

Patch

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,