summaryrefslogtreecommitdiffstats
path: root/Python/fileutils.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-01-04 22:06:14 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-01-04 22:06:14 (GMT)
commitf8693416b5a597627d1f208419b656f13bd7efb8 (patch)
tree05ea4d42d7e4e5e82efd434c0003a78a7e609ab4 /Python/fileutils.c
parent9eb1faf39b0d7cedebbb341453144814e4c1b68f (diff)
parent10ecaa24162382bdf5e21170b27206188ec9b25f (diff)
downloadcpython-f8693416b5a597627d1f208419b656f13bd7efb8.zip
cpython-f8693416b5a597627d1f208419b656f13bd7efb8.tar.gz
cpython-f8693416b5a597627d1f208419b656f13bd7efb8.tar.bz2
merge 3.4 (#23165)
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 0c76e72..c5c8d4e 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -220,8 +220,11 @@ decode_ascii_surrogateescape(const char *arg, size_t *size)
wchar_t *res;
unsigned char *in;
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)
return NULL;
@@ -305,10 +308,15 @@ Py_DecodeLocale(const char* arg, size_t *size)
argsize = mbstowcs(NULL, arg, 0);
#endif
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)
goto oom;
- count = mbstowcs(res, arg, argsize+1);
+ count = mbstowcs(res, arg, argsize);
if (count != (size_t)-1) {
wchar_t *tmp;
/* 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
actual output could use less memory. */
argsize = strlen(arg) + 1;
+ if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t))
+ goto oom;
res = (wchar_t*)PyMem_RawMalloc(argsize*sizeof(wchar_t));
if (!res)
goto oom;