This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: char buffer in function posix_getcwdu should not be fix length
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: os.getcwd() hardcodes max path len
View: 9246
Assigned To: Nosy List: boya, skrah, vstinner
Priority: normal Keywords: patch

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:52adminsetgithub: 51066
2010-07-20 18:58:57skrahsetstatus: open -> closed

resolution: duplicate

type: behavior
stage: resolved
versions: + Python 3.1, Python 2.7, Python 3.2
nosy: + skrah
messages: + msg110947
components: + Extension Modules
superseder: os.getcwd() hardcodes max path len
2009-09-10 18:02:02boyasetfiles: + patch_6817.diff

messages: + msg92497
2009-09-07 23:41:25vstinnersetmessages: + msg92402
2009-09-07 23:34:54vstinnersetnosy: + vstinner
messages: + msg92401
2009-09-02 02:57:44boyacreate