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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/pcre2grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3295,19 +3295,25 @@ if (isdirectory(pathname))

#ifdef HAVE_REALPATH
{
char resolvedpath[PATH_MAX];
char *resolvedpath;
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 :)

continue; /* This path is invalid - we can skip processing this */
isSame = strcmp(pathname, resolvedpath) == 0;
if (isSame) continue; /* We have a recursion */
if (isSame)
{
free(resolvedpath);
continue; /* We have a recursion */
}
rlen = strlen(resolvedpath);
if (rlen++ < sizeof(resolvedpath) - 3)
rlen++;
{
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

strcat(resolvedpath, "/");
contained = strncmp(pathname, resolvedpath, rlen) == 0;
free(resolvedpath);
if (contained) continue; /* We have a recursion */
}
}
Expand Down