-
Notifications
You must be signed in to change notification settings - Fork 31
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
Commit 85a1b79 breaks building Perl5 when using ksh93 as /bin/sh #467
Comments
Yup, I done broke it. :-/ On Linux (but not macOS):
The bug occurs when PWD is not inherited from the environment. |
I introduced a classic use after free problem, very obvious. Sorry about that. Try this patch: diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c
index f106ffa2..9f7e1c17 100644
--- a/src/cmd/ksh93/sh/path.c
+++ b/src/cmd/ksh93/sh/path.c
@@ -183,6 +183,7 @@ static pid_t command_xargs(const char *path, char *argv[],char *const envp[], in
char *path_pwd(void)
{
register char *cp;
+ char tofree = 0;
Namval_t *pwdnod;
/* Don't bother if PWD already set */
if(sh.pwd)
@@ -198,7 +199,6 @@ char *path_pwd(void)
{
/* Check if $HOME is a path to the PWD; this ensures $PWD == $HOME
at login, even if $HOME is a path that contains symlinks */
- char tofree = 0;
cp = nv_getval(sh_scoped(HOME));
if(!(cp && *cp=='/' && test_inode(cp,e_dot)))
{
@@ -214,8 +214,6 @@ char *path_pwd(void)
pwdnod = sh_assignok(pwdnod,1);
nv_putval(pwdnod,cp,NV_RDONLY);
}
- if(tofree)
- free((void*)cp);
}
nv_onattr(pwdnod,NV_EXPORT);
/* Neither obtained the pwd nor can fall back to sane-ish $PWD: fall back to "." */
@@ -224,7 +222,9 @@ char *path_pwd(void)
if(!cp || *cp!='/')
nv_putval(pwdnod,cp=(char*)e_dot,NV_RDONLY);
/* Set shell PWD */
- sh.pwd = sh_strdup(cp);
+ if(!tofree)
+ cp = sh_strdup(cp);
+ sh.pwd = cp;
return((char*)sh.pwd);
}
|
I applied your patch on top of 85a1b79 and Perl5 builds fine now. I also ran bin/shtests but I guess you did that as well. Thank you! |
Thank you for finding and reporting the bug so promptly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Commit 85a1b79 breaks building Perl5 when using ksh93 as /bin/sh
Line 586-587 of cpan/Encode/Makefile looks like this:
Changing directory to cpan/Encode/Byte fails.
If you would like, you can reproduce this in Debian Live under x86_64 QEMU:
Run the following in Debian Live:
Sorry, I know this makes for a pretty poor reproducer but I do not know how to reduce it.
I would happily try any suggested patches.
The text was updated successfully, but these errors were encountered: