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

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

Comments

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

Patch

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)