zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: [MAYBE BUG] resetting `$0' in sourced script causes zsh to crash on Debian
Date: Fri, 6 Nov 2009 21:30:05 +0000	[thread overview]
Message-ID: <20091106213005.372538f0@pws-pc> (raw)
In-Reply-To: <200911061949.32084.stefano.lattarini@gmail.com>

On Fri, 6 Nov 2009 19:49:31 +0100
Stefano Lattarini <stefano.lattarini@gmail.com> wrote:
> I have recently found a problem in resetting `$0' inside a script "sourced"
> with the `.' builtin.
> 
> Not sure if it's a bug or if it's just me doing something that should not
> be done; hopefully you can tell.

Yep, that's a bug.  Thanks for the clear instructions.  The patch makes
valgrind happy, and fits with your description.

(If the shell didn't want you to set $0, it would declare it readonly
and tell you to go it way when you set it.  Since it doesn't you should
be able to set it, and in either case there shouldn't be a memory error.)

By the way, anyone running valgrind is invited to look at the errors in
the code reported.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.235
diff -u -r1.235 builtin.c
--- Src/builtin.c	2 Sep 2009 15:27:35 -0000	1.235
+++ Src/builtin.c	6 Nov 2009 21:26:06 -0000
@@ -4747,7 +4747,7 @@
     enam = arg0 = ztrdup(*argv);
     if (isset(FUNCTIONARGZERO)) {
 	old0 = argzero;
-	argzero = arg0;
+	argzero = ztrdup(arg0);
     }
     s = unmeta(enam);
     errno = ENOENT;
@@ -4802,8 +4802,10 @@
     if (ret == SOURCE_NOT_FOUND)
 	zwarnnam(name, "%e: %s", errno, enam);
     zsfree(arg0);
-    if (old0)
+    if (old0) {
+	zsfree(argzero);
 	argzero = old0;
+    }
     return ret == SOURCE_OK ? lastval : 128 - ret;
 }
 
-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      parent reply	other threads:[~2009-11-06 21:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-06 18:49 Stefano Lattarini
2009-11-06 19:59 ` Dan Nelson
2009-11-06 20:38   ` Mikael Magnusson
2009-11-08 12:05     ` Stefano Lattarini
2009-11-06 21:30 ` Peter Stephenson [this message]

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=20091106213005.372538f0@pws-pc \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@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).