comparison Objects/stringobject.c @ 49716:200c8aab1917 2.4

- Issue #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
author Matthias Klose <doko@ubuntu.com>
date Wed, 12 Nov 2008 07:21:52 +0000
parents 187388c11505
children 61d06409a660
comparison
equal deleted inserted replaced
49715:9781eef3192c 49716:200c8aab1917
50 */ 50 */
51 PyObject * 51 PyObject *
52 PyString_FromStringAndSize(const char *str, int size) 52 PyString_FromStringAndSize(const char *str, int size)
53 { 53 {
54 register PyStringObject *op; 54 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
55 if (size == 0 && (op = nullstring) != NULL) { 62 if (size == 0 && (op = nullstring) != NULL) {
56 #ifdef COUNT_ALLOCS 63 #ifdef COUNT_ALLOCS
57 null_strings++; 64 null_strings++;
58 #endif 65 #endif
59 Py_INCREF(op); 66 Py_INCREF(op);