[PATCH] parsers: strictly check for 20-byte hashes where they're required

Bryan O'Sullivan bos at serpentine.com
Sat May 12 13:34:06 CDT 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1336847133 -7200
# Node ID f974fefc820101f877306a144bee4f4681394fc1
# Parent  76c744e0c5bbd0900beba49787b7e04ba862939b
parsers: strictly check for 20-byte hashes where they're required

diff -r 76c744e0c5bb -r f974fefc8201 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Sat May 12 13:20:26 2012 +0200
+++ b/mercurial/localrepo.py	Sat May 12 20:25:33 2012 +0200
@@ -388,7 +388,7 @@
                 # ignore tags to unknown nodes
                 self.changelog.rev(v)
                 t[k] = v
-            except error.LookupError:
+            except (error.LookupError, ValueError):
                 pass
         return t
 
diff -r 76c744e0c5bb -r f974fefc8201 mercurial/parsers.c
--- a/mercurial/parsers.c	Sat May 12 13:20:26 2012 +0200
+++ b/mercurial/parsers.c	Sat May 12 20:25:33 2012 +0200
@@ -785,7 +785,7 @@
 	if (PyInt_Check(value))
 		return index_get(self, PyInt_AS_LONG(value));
 
-	if (PyString_AsStringAndSize(value, &node, &nodelen) == -1)
+	if (node_check(value, &node, &nodelen) == -1)
 		return NULL;
 	rev = index_find_node(self, node, nodelen);
 	if (rev >= -1)
@@ -868,12 +868,15 @@
 
 static PyObject *index_m_get(indexObject *self, PyObject *args)
 {
+	Py_ssize_t nodelen;
+	PyObject *val;
 	char *node;
-	int nodelen, rev;
+	int rev;
 
-	if (!PyArg_ParseTuple(args, "s#", &node, &nodelen))
+	if (!PyArg_ParseTuple(args, "O", &val))
 		return NULL;
-
+	if (node_check(val, &node, &nodelen) == -1)
+		return NULL;
 	rev = index_find_node(self, node, nodelen);
 	if (rev ==  -3)
 		return NULL;
@@ -892,11 +895,8 @@
 		return rev >= -1 && rev < index_length(self);
 	}
 
-	if (!PyString_Check(value))
-		return 0;
-
-	node = PyString_AS_STRING(value);
-	nodelen = PyString_GET_SIZE(value);
+	if (node_check(value, &node, &nodelen) == -1)
+		return -1;
 
 	switch (index_find_node(self, node, nodelen)) {
 	case -3:


More information about the Mercurial-devel mailing list