Skip to content

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

Closed

Description

@boya
mannequin
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']

    Activity

    1. boya commented on Sep 2, 2009

      boyamannequin
      MannequinAuthor

      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.

    2. vstinner commented on Sep 7, 2009

      @vstinner
      Member

      Your patch is mixing tabs and spaces :-/

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

    3. vstinner commented on Sep 7, 2009

      @vstinner
      Member

      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.

    4. boya commented on Sep 10, 2009

      boyamannequin
      MannequinAuthor

      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);
      	}
    5. skrah commented on Jul 20, 2010

      skrahmannequin
      Mannequin

      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.

    6. added
      type-bugAn unexpected behavior, bug, or error
      on Jul 20, 2010
    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions