mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
merge 3.4 (#23165)
This commit is contained in:
commit
f8693416b5
2 changed files with 16 additions and 3 deletions
|
@ -193,6 +193,9 @@ Core and Builtins
|
||||||
exception. In versions prior to 3.5, '#' with 'c' had no effect. Now
|
exception. In versions prior to 3.5, '#' with 'c' had no effect. Now
|
||||||
specifying it is an error. Patch by Torsten Landschoff.
|
specifying it is an error. Patch by Torsten Landschoff.
|
||||||
|
|
||||||
|
- Issue #23165: Perform overflow checks before allocating memory in the
|
||||||
|
_Py_char2wchar function.
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
|
@ -220,8 +220,11 @@ decode_ascii_surrogateescape(const char *arg, size_t *size)
|
||||||
wchar_t *res;
|
wchar_t *res;
|
||||||
unsigned char *in;
|
unsigned char *in;
|
||||||
wchar_t *out;
|
wchar_t *out;
|
||||||
|
size_t argsize = strlen(arg) + 1;
|
||||||
|
|
||||||
res = PyMem_RawMalloc((strlen(arg)+1)*sizeof(wchar_t));
|
if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t))
|
||||||
|
return NULL;
|
||||||
|
res = PyMem_RawMalloc(argsize*sizeof(wchar_t));
|
||||||
if (!res)
|
if (!res)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -305,10 +308,15 @@ Py_DecodeLocale(const char* arg, size_t *size)
|
||||||
argsize = mbstowcs(NULL, arg, 0);
|
argsize = mbstowcs(NULL, arg, 0);
|
||||||
#endif
|
#endif
|
||||||
if (argsize != (size_t)-1) {
|
if (argsize != (size_t)-1) {
|
||||||
res = (wchar_t *)PyMem_RawMalloc((argsize+1)*sizeof(wchar_t));
|
if (argsize == PY_SSIZE_T_MAX)
|
||||||
|
goto oom;
|
||||||
|
argsize += 1;
|
||||||
|
if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t))
|
||||||
|
goto oom;
|
||||||
|
res = (wchar_t *)PyMem_RawMalloc(argsize*sizeof(wchar_t));
|
||||||
if (!res)
|
if (!res)
|
||||||
goto oom;
|
goto oom;
|
||||||
count = mbstowcs(res, arg, argsize+1);
|
count = mbstowcs(res, arg, argsize);
|
||||||
if (count != (size_t)-1) {
|
if (count != (size_t)-1) {
|
||||||
wchar_t *tmp;
|
wchar_t *tmp;
|
||||||
/* Only use the result if it contains no
|
/* Only use the result if it contains no
|
||||||
|
@ -331,6 +339,8 @@ Py_DecodeLocale(const char* arg, size_t *size)
|
||||||
/* Overallocate; as multi-byte characters are in the argument, the
|
/* Overallocate; as multi-byte characters are in the argument, the
|
||||||
actual output could use less memory. */
|
actual output could use less memory. */
|
||||||
argsize = strlen(arg) + 1;
|
argsize = strlen(arg) + 1;
|
||||||
|
if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t))
|
||||||
|
goto oom;
|
||||||
res = (wchar_t*)PyMem_RawMalloc(argsize*sizeof(wchar_t));
|
res = (wchar_t*)PyMem_RawMalloc(argsize*sizeof(wchar_t));
|
||||||
if (!res)
|
if (!res)
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue