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

Avoid use of PATH_MAX (Debian bug #1009066) #98

Closed

Conversation

MatthewVernon
Copy link
Contributor

PATH_MAX is undefined on GNU Hurd (as is allowed by POSIX), and is in
some regards problematic anyway (cf
https://www.gnu.org/software/hurd/hurd/porting/guidelines.html#PATH_MAX_tt_MAX_PATH_tt_MAXPATHL
).

This patch from Yavor Doganov instead dynamically allocates
*resolvedpath as necessary using realpath(childpath, NULL) (and
then makes sure to free it later).

Signed-off-by: Matthew Vernon matthew@debian.org

PATH_MAX is undefined on GNU Hurd (as is allowed by POSIX), and is in
some regards problematic anyway (cf
https://www.gnu.org/software/hurd/hurd/porting/guidelines.html#PATH_MAX_tt_MAX_PATH_tt_MAXPATHL
).

This patch from Yavor Doganov instead dynamically allocates
`*resolvedpath` as necessary using `realpath(childpath, NULL)` (and
then makes sure to free it later).

Signed-off-by: Matthew Vernon <matthew@debian.org>
Copy link
Contributor

@carenas carenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO an implementation that still uses a provided buffer (which is malloc for HURD) would be better, and might allow also avoid the problematic use of realloc or multiple free.

BOOL isSame;
size_t rlen;
if (realpath(childpath, resolvedpath) == NULL)
if ((resolvedpath = realpath(childpath, NULL)) == NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realpath(path, NULL) is only valid in POSIX.1-2008, so we would need to check for that and enable this code conditionally based on that.

IMHO, since only Hurd doesn't have PATH_MAX even when it provides realpath(), the current code is more portable, and was indeed fixed so it will be just ignored in Hurd since adf76fa

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thanks, yes the right answer is to cherry-pick adf76fa on top of my Debian tree; so I'll do that and close this.
Thanks for the pointer :)

{
BOOL contained;
resolvedpath = (char *)realloc(resolvedpath, rlen + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could fail and in that case the original resolvedpath might leak, and more importantly will crash next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants