summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-10-27 21:29:13 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-10-27 21:29:13 (GMT)
commit06ba3d34b4c2726dc9bf0a5cd4588fcb9c343e55 (patch)
tree4e8951c52294833a6dd798530eec0d4c0bde514b /PC
parentbc6830c9486ed7d48d5ac2ea56f0d8309872abbf (diff)
parentc6dd415252f255b583fcdae5d51a28e027284b06 (diff)
downloadcpython-06ba3d34b4c2726dc9bf0a5cd4588fcb9c343e55.zip
cpython-06ba3d34b4c2726dc9bf0a5cd4588fcb9c343e55.tar.gz
cpython-06ba3d34b4c2726dc9bf0a5cd4588fcb9c343e55.tar.bz2
Issue #28522: Fixes mishandled buffer reallocation in getpathp.c
Diffstat (limited to 'PC')
-rw-r--r--PC/getpathp.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c
index 31f973e..0b0ae49 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -581,7 +581,8 @@ read_pth_file(const wchar_t *path, wchar_t *prefix, int *isolated, int *nosite)
wn = MultiByteToWideChar(CP_UTF8, 0, line, -1, wline, wn + 1);
wline[wn] = '\0';
- while (wn + prefixlen + 4 > bufsiz) {
+ size_t usedsiz = wcslen(buf);
+ while (usedsiz + wn + prefixlen + 4 > bufsiz) {
bufsiz += MAXPATHLEN;
buf = (wchar_t*)PyMem_RawRealloc(buf, (bufsiz + 1) * sizeof(wchar_t));
if (!buf) {
@@ -590,11 +591,21 @@ read_pth_file(const wchar_t *path, wchar_t *prefix, int *isolated, int *nosite)
}
}
- if (buf[0])
+ if (usedsiz) {
wcscat_s(buf, bufsiz, L";");
+ usedsiz += 1;
+ }
- wchar_t *b = &buf[wcslen(buf)];
- wcscat_s(buf, bufsiz, prefix);
+ errno_t result;
+ _Py_BEGIN_SUPPRESS_IPH
+ result = wcscat_s(buf, bufsiz, prefix);
+ _Py_END_SUPPRESS_IPH
+ if (result == EINVAL) {
+ Py_FatalError("invalid argument during ._pth processing");
+ } else if (result == ERANGE) {
+ Py_FatalError("buffer overflow during ._pth processing");
+ }
+ wchar_t *b = &buf[usedsiz];
join(b, wline);
PyMem_RawFree(wline);