[PATCH 5 of 6 cpychecker] parsers: set exception when there's too little string data to extract parents

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


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1439930410 14400
#      Tue Aug 18 16:40:10 2015 -0400
# Node ID b9c2bab361f6abe80f7a155ba7910cf0a6bd90d8
# Parent  2c553a1aae96d666002313c6c04acda080eaeff4
parsers: set exception when there's too little string data to extract parents

Previously we were returning NULL from this function without actually
setting up an exception. This fixes that problem, which was detected
with cpychecker.

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -481,8 +481,11 @@ static PyObject *parse_dirstate(PyObject
 	len = readlen;
 
 	/* read parents */
-	if (len < 40)
+	if (len < 40) {
+		PyErr_SetString(
+			PyExc_ValueError, "too little data for parents");
 		goto quit;
+	}
 
 	parents = Py_BuildValue("s#s#", str, 20, str + 20, 20);
 	if (!parents)


More information about the Mercurial-devel mailing list