diff options
| author | Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-10-21 08:56:50 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-21 08:56:50 (GMT) |
| commit | 3dec84f40ef49bab994a1af4e6082bf81021feab (patch) | |
| tree | 663bf37bc26e53b72a392feb2bd10e2e1f093cb1 /Python | |
| parent | e945052e07bb7f3061b5fdb4735c892cdda3aefc (diff) | |
| download | cpython-3dec84f40ef49bab994a1af4e6082bf81021feab.zip cpython-3dec84f40ef49bab994a1af4e6082bf81021feab.tar.gz cpython-3dec84f40ef49bab994a1af4e6082bf81021feab.tar.bz2 | |
bpo-38540: Fix possible leak in PyArg_Parse for "esGH-" and "etGH-". (GH-16869)
(cherry picked from commit 5bc6a7c06eda20ba131ecba6752be0506d310181)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/getargs.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 73e47f8..c3895d1 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1176,7 +1176,19 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, trailing 0-byte */ - FETCH_SIZE; + int *q = NULL; Py_ssize_t *q2 = NULL; + if (flags & FLAG_SIZE_T) { + q2 = va_arg(*p_va, Py_ssize_t*); + } + else { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) + { + Py_DECREF(s); + return NULL; + } + q = va_arg(*p_va, int*); + } format++; if (q == NULL && q2 == NULL) { @@ -1209,7 +1221,19 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, } } memcpy(*buffer, ptr, size+1); - STORE_SIZE(size); + + if (flags & FLAG_SIZE_T) { + *q2 = size; + } + else { + if (INT_MAX < size) { + Py_DECREF(s); + PyErr_SetString(PyExc_OverflowError, + "size does not fit in an int"); + return converterr("", arg, msgbuf, bufsize); + } + *q = (int)size; + } } else { /* Using a 0-terminated buffer: |
