Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

$HOME not set and zsh crashing in emulation mode



  A simple reproducer:

"""
$ cat t.sh
#!/bin/sh
echo $HOME

$ ln -sf /bin/zsh ksh

$ ./ksh -n t.sh
Segmentation fault (core dumped)
"""

  This probably is not correct, but a possible patch is:
---8<---
--- zsh-5.0.2/Src/init.c.orig    2016-10-27 15:36:29.210875166 -0200
+++ zsh-5.0.2/Src/init.c    2016-10-27 15:36:33.581867451 -0200
@@ -963,7 +963,7 @@ setupvals(void)
     if (EMULATION(EMULATE_ZSH))
     ptr = home;
     else
-    ptr = zgetenv("HOME");
+    ptr = home = zgetenv("HOME");
     if (ptr && ispwd(ptr))
     pwd = ztrdup(ptr);
     else if ((ptr = zgetenv("PWD")) && (strlen(ptr) < PATH_MAX) &&
---8<---

  The problem happens because when importing the
environment, setstrvalue will return too early with -n,
but will always set HOME if not in emulation mode:

mod_export void
setstrvalue(Value v, char *val)
{
    if (unset(EXECOPT))
    return;

  From gdb:

(gdb) b setstrvalue
(gdb) cond 1 (strcmp(val, "/home/pcpa") == 0)
Breakpoint 1, setstrvalue (val=0x6e0b00 "/home/pcpa",
v=0x7fffffffd950) at params.c:2267
2267        if (unset(EXECOPT))
(gdb) bt
#0  setstrvalue (val=0x6e0b00 "/home/pcpa", v=0x7fffffffd950) at params.c:2267
#1  assignsparam (s=0x7ffff7ff5cc4 "", s@entry=0x7ffff7ff5cc0 "HOME",
val=0x6e0b00 "/home/pcpa", flags=<optimized out>, flags@entry=0)
    at params.c:2738
#2  0x00000000004712fe in createparamtable () at params.c:737
#3  0x000000000044823f in setupvals () at init.c:988
#4  0x000000000044a1ac in zsh_main (argc=<optimized out>,
argv=<optimized out>) at init.c:1596
#5  0x000000000040e3f0 in main (argc=3, argv=0x7fffffffde78) at ./main.c:93

Thanks,
Paulo



Messages sorted by: Reverse Date, Date, Thread, Author