Skip to content

Commit b7cfda1

Browse files
committed
- Issue python#2587: In the C API, PyString_FromStringAndSize() takes a signed size
parameter but was not verifying that it was greater than zero. Values less than zero will now raise a SystemError and return NULL to indicate a bug in the calling C code. CVE-2008-1887. backport r62261, r62271
1 parent 8af5d57 commit b7cfda1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Misc/NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Core and builtins
3030
- Issues #2588, #2589: Fix potential integer underflow and overflow
3131
conditions in the PyOS_vsnprintf C API function. CVE-2008-3144.
3232

33+
- Issue #2587: In the C API, PyString_FromStringAndSize() takes a signed size
34+
parameter but was not verifying that it was greater than zero. Values
35+
less than zero will now raise a SystemError and return NULL to indicate a
36+
bug in the calling C code. CVE-2008-1887.
37+
3338
Extension Modules
3439
-----------------
3540

Objects/stringobject.c

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ PyObject *
5252
PyString_FromStringAndSize(const char *str, int size)
5353
{
5454
register PyStringObject *op;
55+
56+
if (size < 0) {
57+
PyErr_SetString(PyExc_SystemError,
58+
"Negative size passed to PyString_FromStringAndSize");
59+
return NULL;
60+
}
61+
5562
if (size == 0 && (op = nullstring) != NULL) {
5663
#ifdef COUNT_ALLOCS
5764
null_strings++;

0 commit comments

Comments
 (0)