From: Anatol Belski Date: Sat, 21 Jan 2017 01:11:24 +0000 (+0100) Subject: ensure the string for conversion is \0 terminated and integrade X-Git-Tag: php-7.1.2RC1~39 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b6122a9570156272a11f54625ffafd672e38aba;p=php ensure the string for conversion is \0 terminated and integrade additional path length check --- diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 9c2dc29299..b5e099848a 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -916,6 +916,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i char *printname = NULL, *substitutename = NULL; size_t substitutename_len; int substitutename_off = 0; + wchar_t tmpsubstname[MAXPATHLEN]; if(++(*ll) > LINK_MAX) { free_alloca(tmp, use_heap); @@ -959,8 +960,15 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i } substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR); - substitutename = php_win32_cp_conv_w_to_any(reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), - substitutename_len, &substitutename_len); + if (substitutename_len > MAXPATHLEN) { + free_alloca(pbuffer, use_heap_large); + free_alloca(tmp, use_heap); + FREE_PATHW() + return -1; + } + memmove(tmpsubstname, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), pbuffer->MountPointReparseBuffer.SubstituteNameLength); + tmpsubstname[substitutename_len] = L'\0'; + substitutename = php_win32_cp_conv_w_to_any(tmpsubstname, substitutename_len, &substitutename_len); if (!substitutename) { free_alloca(pbuffer, use_heap_large); free_alloca(tmp, use_heap); @@ -982,8 +990,15 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR); - substitutename = php_win32_cp_conv_w_to_any(reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), - substitutename_len, &substitutename_len); + if (substitutename_len > MAXPATHLEN) { + free_alloca(pbuffer, use_heap_large); + free_alloca(tmp, use_heap); + FREE_PATHW() + return -1; + } + memmove(tmpsubstname, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), pbuffer->MountPointReparseBuffer.SubstituteNameLength); + tmpsubstname[substitutename_len] = L'\0'; + substitutename = php_win32_cp_conv_w_to_any(tmpsubstname, substitutename_len, &substitutename_len); if (!substitutename) { free_alloca(pbuffer, use_heap_large); free_alloca(tmp, use_heap);