From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15934 invoked by alias); 16 Jun 2015 03:50:54 -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: 35482 Received: (qmail 18229 invoked from network); 16 Jun 2015 03:50:52 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=7C0d7YUFXGb+PxvLlt7QQxaz82WtOq7Ut6GnXUjFWbA=; b=KtahqRjI7T+81Akmv9ST3HVCVKV17F/anYAX0qre0Lr7F1X5mzDJwtrCNOTQOAcE6B FiUcg2WO1U8Gq4hTynxTFSxQroY7nKacJ8VaM2zBifoFgAjXrRLw51i2TyomIoKkNrAS rHGBi4/VVePFyY+n1+oRlbdirer1lUHonc7UpYIHf491vBzZOTmhcDzwnh6jakO5N5t8 MNqGNkYvm1CGQ/vi1fm17gNcjfeRsUnDt5IHLqF16CekH937WZRyNQ4BelKIf7ZlQpiT e/5Xwn0XC7G6GBvmCfovy7dT1sahjq1lAYcC7MI4kSZN9TK3Q7vBW0d2/rzfJrdgj9Xu RyVQ== X-Gm-Message-State: ALoCoQmADqKA1+82VZM4/nnOxMZk/4eA/h3Qg5dh6mBVetV+KUOQwS/EbgNSKdOfv7NbNyszJLxn X-Received: by 10.202.78.214 with SMTP id c205mr5856052oib.131.1434426648031; Mon, 15 Jun 2015 20:50:48 -0700 (PDT) From: Bart Schaefer Message-Id: <150615205044.ZM25959@torch.brasslantern.com> Date: Mon, 15 Jun 2015 20:50:44 -0700 In-Reply-To: <1434411879-12403-1-git-send-email-mikachu@gmail.com> Comments: In reply to Mikael Magnusson "PATCH: Allow setting $0 when POSIX_ARGZERO is not set" (Jun 16, 1:44am) References: <1434411879-12403-1-git-send-email-mikachu@gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: PATCH: Allow setting $0 when POSIX_ARGZERO is not set MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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. 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