Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Allow setting $0 when POSIX_ARGZERO is not set
- X-seq: zsh-workers 35485
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: PATCH: Allow setting $0 when POSIX_ARGZERO is not set
- Date: Tue, 16 Jun 2015 08:25:14 +0200
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=hIS+IkRRQ5ES9emEP6Jv0JE9hWwyYppcrWMkyjGnXWY=; b=amBDq2rjsEd9Cg+IPcQf+RdMPeH5Kgt0EDmF8x+Kcy505X3KwGPptVsoYDbZdfLyhU W62FIGvJMPecCYuhpUyPWoITi5aqwkjlmKesN+CTdamgfhtR+it1IGY5vYcUpEog24ps 4ogMXDvQt8oPc7KIfXE2teEUB5tMbJxTay7nj+UXdAyzFdt5CwUGgPRxrQZ1X3JiFof9 sgPtmwy1Ol1RvbrsgfiigIVTpOganiw0N9mPHRQI69p8ww3uEzWH+dEOjkDqhtteMc6k 9Tklc0z3b39zriOi94zPN92N1EQoc+DvlMQns12Gs5SKHB8iBw2VKiUuCCgQvbB8O3Qo iFiw==
- In-reply-to: <150615205044.ZM25959@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1434411879-12403-1-git-send-email-mikachu@gmail.com> <150615205044.ZM25959@torch.brasslantern.com>
On Tue, Jun 16, 2015 at 5:50 AM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Jun 16, 1:44am, Mikael Magnusson wrote:
> }
> } I don't think this should hurt anything.
>
> When sourcing a script the global argzero (which has been initialized
> from runscript) is not malloc'd memory.
>
> ==25941== Invalid free() / delete / delete[]
> ==25941== at 0x4004EFA: free (vg_replace_malloc.c:235)
> ==25941== by 0x80950D7: zsfree (mem.c:1828)
> ==25941== by 0x80A4DE9: argzerosetfn (params.c:4055)
> ==25941== by 0x80A0CDF: assignstrvalue (params.c:2349)
> ==25941== by 0x80A22D2: assignsparam (params.c:2806)
> ==25941== by 0x806642F: addvars (exec.c:2317)
> ==25941== by 0x80635F0: execsimple (exec.c:1117)
> ==25941== by 0x80639AD: execlist (exec.c:1247)
> ==25941== by 0x80634D1: execode (exec.c:1074)
> ==25941== by 0x807F4EC: loop (init.c:207)
> ==25941== by 0x808290B: zsh_main (init.c:1674)
> ==25941== by 0x804C2E9: main (main.c:93)
> ==25941== Address 0xBEEAFA62 is on thread 1's stack
>
> I'm not sure if this comes up anywhere else. I wasn't trivially able
> to make it fail.
>
> I think it would cause leaks to have parseargs() call ztrdup() for its
> runscript argument, so it looks like setupshin() should do so when
> assigning to argzero.
>
> There are probably other race conditions if a signal were to arrive
> while the shell is still initializing state. Maybe we should get a
> queue_signals() in there somewhere early.
Oh, in that case maybe it's a lot more trouble than it's worth...
> diff --git a/Src/init.c b/Src/init.c
> index 102276a..0fe4d75 100644
> --- a/Src/init.c
> +++ b/Src/init.c
> @@ -1117,8 +1117,9 @@ setupshin(char *runscript)
> exit(127);
> }
> scriptfilename = sfname;
> - zsfree(argzero); /* ztrdup'd in parseargs */
> - argzero = runscript;
> + sfname = argzero; /* copy to avoid race condition */
> + argzero = ztrdup(runscript);
> + zsfree(sfname); /* argzero ztrdup'd in parseargs */
> }
> /*
> * We only initialise line numbering once there is a script to
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author