zsh-users
 help / color / mirror / code / Atom feed
From: "Paulo César Pereira de Andrade" <paulo.cesar.pereira.de.andrade@gmail.com>
To: zsh-users@zsh.org
Subject: $HOME not set and zsh crashing in emulation mode
Date: Thu, 27 Oct 2016 15:51:43 -0200	[thread overview]
Message-ID: <CAHAq8pEPk41cxWdqyBLawsbadAt+JUBnv59nZbNLkte8nfX0iw@mail.gmail.com> (raw)

  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


             reply	other threads:[~2016-10-27 19:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27 17:51 Paulo César Pereira de Andrade [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHAq8pEPk41cxWdqyBLawsbadAt+JUBnv59nZbNLkte8nfX0iw@mail.gmail.com \
    --to=paulo.cesar.pereira.de.andrade@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).