classification
Title: char buffer in function posix_getcwdu should not be fix length
Type: Stage:
Components: Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: boya, haypo (2)
Priority: Keywords patch

Created on 2009-09-02 02:57 by boya, last changed 2009-09-10 18:02 by boya.

Files
File name Uploaded Description Edit Remove
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 (4)
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 (haypo) 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 (haypo) 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);
	}
History
Date User Action Args
2009-09-10 18:02:02boyasetfiles: + patch_6817.diff

messages: + msg92497
2009-09-07 23:41:25hayposetmessages: + msg92402
2009-09-07 23:34:54hayposetnosy: + haypo
messages: + msg92401
2009-09-02 02:57:44boyacreate