10000 [2.7] bpo-38540: Fix possible leak in PyArg_Parse for "es#" and "et#"… · python/cpython@ccdfeb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit ccdfeb7

Browse files
[2.7] bpo-38540: Fix possible leak in PyArg_Parse for "es#" and "et#". (GH-16869). (GH-16877)
(cherry picked from commit 5bc6a7c)
1 parent c9ed34f commit ccdfeb7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed possible leak in :c:func:`PyArg_Parse` and similar functions for
2+
format units ``"es#"`` and ``"et#"`` when the macro
3+
:c:macro:`PY_SSIZE_T_CLEAN` is not defined.

Python/getargs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,19 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
11561156
memcpy(*buffer,
11571157
PyString_AS_STRING(s),
11581158
size + 1);
1159-
STORE_SIZE(size);
1159+
1160+
if (flags & FLAG_SIZE_T) {
1161+
*q2 = size;
1162+
}
1163+
else {
1164+
if (INT_MAX < size) {
1165+
Py_DECREF(s);
1166+
PyErr_SetString(PyExc_OverflowError,
1167+
"size does not fit in an int");
1168+
return converterr("", arg, msgbuf, bufsize);
1169+
}
1170+
*q = (int)size;
1171+
}
11601172
} else {
11611173
/* Using a 0-terminated buffer:
11621174

0 commit comments

Comments
 (0)
0