From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6418 invoked by alias); 16 Jun 2015 06:25:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35485 Received: (qmail 14512 invoked from network); 16 Jun 2015 06:25:18 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 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== MIME-Version: 1.0 X-Received: by 10.107.131.200 with SMTP id n69mr31195602ioi.53.1434435914600; Mon, 15 Jun 2015 23:25:14 -0700 (PDT) In-Reply-To: <150615205044.ZM25959@torch.brasslantern.com> References: <1434411879-12403-1-git-send-email-mikachu@gmail.com> <150615205044.ZM25959@torch.brasslantern.com> Date: Tue, 16 Jun 2015 08:25:14 +0200 Message-ID: Subject: Re: PATCH: Allow setting $0 when POSIX_ARGZERO is not set From: Mikael Magnusson To: Bart Schaefer Cc: zsh workers Content-Type: text/plain; charset=UTF-8 On Tue, Jun 16, 2015 at 5:50 AM, Bart Schaefer 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