Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

char buffer in function posix_getcwdu should not be fix length #51066

Closed
boya mannequin opened this issue Sep 2, 2009 · 5 comments
Closed

char buffer in function posix_getcwdu should not be fix length #51066

boya mannequin opened this issue Sep 2, 2009 · 5 comments
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@boya
Copy link
Mannequin

boya mannequin commented Sep 2, 2009

BPO 6817
Nosy @vstinner, @skrah
Superseder
  • bpo-9246: os.getcwd() hardcodes max path len
  • Files
  • patch_get_cwdu.diff: Patch to make char buffer not fixed length
  • patch_6817.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-07-20.18:58:57.419>
    created_at = <Date 2009-09-02.02:57:44.744>
    labels = ['extension-modules', 'type-bug']
    title = 'char buffer in function posix_getcwdu should not be fix length'
    updated_at = <Date 2010-07-20.18:58:57.416>
    user = 'https://bugs.python.org/boya'

    bugs.python.org fields:

    activity = <Date 2010-07-20.18:58:57.416>
    actor = 'skrah'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-07-20.18:58:57.419>
    closer = 'skrah'
    components = ['Extension Modules']
    creation = <Date 2009-09-02.02:57:44.744>
    creator = 'boya'
    dependencies = []
    files = ['14818', '14874']
    hgrepos = []
    issue_num = 6817
    keywords = ['patch']
    message_count = 5.0
    messages = ['92151', '92401', '92402', '92497', '110947']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'skrah', 'boya']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '9246'
    type = 'behavior'
    url = 'https://bugs.python.org/issue6817'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @boya
    Copy link
    Mannequin Author

    boya mannequin commented Sep 2, 2009

    This issue is similar to bpo-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.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 7, 2009

    Your patch is mixing tabs and spaces :-/

    A "free(tmpbuf);" is missing in "if (res == NULL) return posix_error();".

    @vstinner
    Copy link
    Member

    vstinner commented Sep 7, 2009

    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.

    @boya
    Copy link
    Mannequin Author

    boya mannequin commented Sep 10, 2009

    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);
    	}

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Jul 20, 2010

    I'm marking this as a duplicate of bpo-9246. It's better to change
    py3k and 2.7 in sync. The patches here will not be lost.

    @skrah skrah mannequin added the extension-modules C modules in the Modules dir label Jul 20, 2010
    @skrah skrah mannequin closed this as completed Jul 20, 2010
    @skrah skrah mannequin added the type-bug An unexpected behavior, bug, or error label Jul 20, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant