Issue 6817: char buffer in function posix_getcwdu should not be fix length (original) (raw)

Created on 2009-09-02 02:57 by boya, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch_get_cwdu.diff boya,2009-09-02 02:57 Patch to make char buffer not fixed length
patch_6817.diff boya,2009-09-10 18:02
Messages (5)
msg92151 - (view) Author: Boya Sun (boya) Date: 2009-09-02 02:57
This issue is similar to issue 2722 (http://bugs.python.org/issue2722#), where the char buffer support that the path string has not fixed length in the function posix_getcwd(). In the function posix_getcwdu(), the char buffer is still fix length. But I think the same change should also apply to this function. A patch is attached to allow the char buffer in posix_getcwdu() to be not fixed length.
msg92401 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-09-07 23:34
Your patch is mixing tabs and spaces :-/ A "free(tmpbuf);" is missing in "if (res == NULL) return posix_error();".
msg92402 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-09-07 23:41
The "#ifdef MS_WINDOWS" is not a the right place in posix_getcwdu(): buf and res are declared but unused, and there is dead code on Windows. The patch only fixes the UNIX implementation, not the Windows implementation. In the py3k branch, bytes and unicode versions of getcwd are factorized in a common function. The same should be done in python trunk.
msg92497 - (view) Author: Boya Sun (boya) Date: 2009-09-10 18:02
Victor, I corrected both issues of the patch according to your first comment. This patch did not fix the Windows implementation. It seems that there will not be buffer overflow in the Windows implementation, since if the buffer is small for GetCurrentDirectoryW(), the code allocates a new buffer for it with enough length by the following code: len = GetCurrentDirectoryW(sizeof wbuf/ sizeof wbuf[0], wbuf); if (len >= sizeof wbuf/ sizeof wbuf[0]) { wbuf2 = malloc(len * sizeof(wchar_t)); if (wbuf2) len = GetCurrentDirectoryW(len, wbuf2); }
msg110947 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-07-20 18:58
I'm marking this as a duplicate of issue 9246. It's better to change py3k and 2.7 in sync. The patches here will not be lost.
History
Date User Action Args
2022-04-11 14:56:52 admin set github: 51066
2010-07-20 18:58:57 skrah set status: open -> closedresolution: duplicatetype: behaviorstage: resolvedversions: + Python 3.1, Python 2.7, Python 3.2nosy: + skrahmessages: + components: + Extension Modulessuperseder: os.getcwd() hardcodes max path len
2009-09-10 18:02:02 boya set files: + patch_6817.diffmessages: +
2009-09-07 23:41:25 vstinner set messages: +
2009-09-07 23:34:54 vstinner set nosy: + vstinnermessages: +
2009-09-02 02:57:44 boya create