Kaydet (Commit) f8247796 authored tarafından Hirokazu Yamamoto's avatar Hirokazu Yamamoto

Issue #3813: cannot lanch python.exe via symbolic link on cygwin.

readlink(2) can return non-null-terminated string.
Reviewed by Amaury Forgeot d'Arc.
üst 29d95eb6
...@@ -183,6 +183,7 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) ...@@ -183,6 +183,7 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
cbuf[res] = '\0'; /* buf will be null terminated */
r1 = mbstowcs(buf, cbuf, bufsiz); r1 = mbstowcs(buf, cbuf, bufsiz);
if (r1 == -1) { if (r1 == -1) {
errno = EINVAL; errno = EINVAL;
...@@ -559,8 +560,6 @@ calculate_path(void) ...@@ -559,8 +560,6 @@ calculate_path(void)
wchar_t tmpbuffer[MAXPATHLEN+1]; wchar_t tmpbuffer[MAXPATHLEN+1];
int linklen = _Py_wreadlink(progpath, tmpbuffer, MAXPATHLEN); int linklen = _Py_wreadlink(progpath, tmpbuffer, MAXPATHLEN);
while (linklen != -1) { while (linklen != -1) {
/* It's not null terminated! */
tmpbuffer[linklen] = '\0';
if (tmpbuffer[0] == SEP) if (tmpbuffer[0] == SEP)
/* tmpbuffer should never be longer than MAXPATHLEN, /* tmpbuffer should never be longer than MAXPATHLEN,
but extra check does not hurt */ but extra check does not hurt */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment