zsh-users
 help / color / mirror / code / Atom feed
* $HOME not set and zsh crashing in emulation mode
@ 2016-10-27 17:51 Paulo César Pereira de Andrade
  2016-10-27 20:27 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Paulo César Pereira de Andrade @ 2016-10-27 17:51 UTC (permalink / raw)
  To: zsh-users

  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


^ permalink raw reply	[flat|nested] 4+ messages in thread
[parent not found: <CAHAq8pEPk41cxWdqyBLawsbadAt+JUBnv59nZbNLkte8nfX0iw__31688.0478793339$1477597412$gmane$org@mail.gmail.com>]

end of thread, other threads:[~2016-10-28 13:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-27 17:51 $HOME not set and zsh crashing in emulation mode Paulo César Pereira de Andrade
2016-10-27 20:27 ` Bart Schaefer
     [not found] <CAHAq8pEPk41cxWdqyBLawsbadAt+JUBnv59nZbNLkte8nfX0iw__31688.0478793339$1477597412$gmane$org@mail.gmail.com>
2016-10-27 20:19 ` Daniel Shahaf
2016-10-28 12:04   ` Paulo César Pereira de Andrade

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).