2
0
Эх сурвалжийг харах

Ensure we don't run past the end of the tree text.

We use strnlen so we can find namelen even if the buffer is truncated
in the name. This is not necessary for Python string objects, which are
guaranteed to be null-terminated, but some buffer objects (e.g. mmap)
may not be.
Dave Borowitz 15 жил өмнө
parent
commit
65a53fca3c

+ 3 - 2
dulwich/_objects.c

@@ -37,7 +37,7 @@ static PyObject *sha_to_pyhex(const unsigned char *sha)
 
 
 static PyObject *py_parse_tree(PyObject *self, PyObject *args)
 static PyObject *py_parse_tree(PyObject *self, PyObject *args)
 {
 {
-	char *text, *end;
+	char *text, *start, *end;
 	int len, namelen;
 	int len, namelen;
 	PyObject *ret, *item, *name;
 	PyObject *ret, *item, *name;
 
 
@@ -52,6 +52,7 @@ static PyObject *py_parse_tree(PyObject *self, PyObject *args)
 		return NULL;
 		return NULL;
 	}
 	}
 
 
+	start = text;
 	end = text + len;
 	end = text + len;
 
 
 	while (text < end) {
 	while (text < end) {
@@ -66,7 +67,7 @@ static PyObject *py_parse_tree(PyObject *self, PyObject *args)
 
 
 		text++;
 		text++;
 
 
-		namelen = strlen(text);
+		namelen = strnlen(text, len - (text - start));
 
 
 		name = PyString_FromStringAndSize(text, namelen);
 		name = PyString_FromStringAndSize(text, namelen);
 		if (name == NULL) {
 		if (name == NULL) {