|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-04-16 18:15 UTC] jan dot starke at t-systems dot com
Description:
------------
The Windows API functions GetFinalPathNameByHandleA, which is used by php_sys_readlink, has two different ways of returning an error:
(1) the return value is different from cchFilePath (which is MAXPATHLEN in php_sys_readlink). This error is raised if the buffer to store the pathname is not large enough to hold the pathname.
(2) the return value is zero. This error can be caused by one of ERROR_PATH_NOT_FOUND, ERROR_NOT_ENOUGH_MEMORY or ERROR_INVALID_PARAMETER.
Unfortunately, the second case is not handled by php_sys_readlink. As a result, php_sys_readlink writes an empty string to target and returns 0 as its length, which both is incorrect.
Expected result:
----------------
php_sys_readlink should return -1 if GetFinalPathNameByHandleA returns 0:
<code>
if (dwRet >= MAXPATHLEN || dwRet == 0) {
return -1;
}
</code>
Actual result:
--------------
if GetFinalPathNameByHandleA returns 0, php_sys_readlink returns 0 :-(
This brakes php_check_specific_open_basedir, which in our case creates some problems
<code>
if (dwRet >= MAXPATHLEN) {
return -1;
}
</code>
Patches0001-fix-69472-return-value-0-by-GetFinalPathNameByHandle.patch (last revision 2015-04-16 19:12 UTC by jan dot starke at outofbed dot org)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
No, we are not using the patched versions. Our policies enforce us to use official releases only. But we have some testing environments where we can test such patches. However, during our test we did not see something interesting in our logs. Could you give me a hint? Today, I added some debug code: dwRet = pGetFinalPathNameByHandle(hFile, target, MAXPATHLEN, VOLUME_NAME_DOS); if (dwRet == 0) { FILE* teeshop_fh; teeshop_fh = fopen("C:\\Temp\\GetFinalPathNameByHandle.log", "a"); fprintf(teeshop_fh, "GetFinalPathNameByHandle('%s') returned 0x%08x\n", link, GetLastError()); fclose(teeshop_fh); return -1; } if(dwRet >= MAXPATHLEN) { return -1; } We observed that GetFinalPathNameByHandle returns 0xb7 (ERROR_ALREADY_EXISTS). Unfortunately, this error should never be raised by this function (according to Microsoft's documentation). I assume this error is returned by NtQueryObject, but I do not really know. Does it make sense to post a bug to Microsoft? In my eyes it is impossible to create a working testcase, because we cannot reliably create the error context. We should assume that GetFinalPathNameByHandle may return 0 in any case, without knowing the cause. Regards, Jan