zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Dan Nelson <dnelson@allantgroup.com>
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, 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:38:42 +0100	[thread overview]
Message-ID: <237967ef0911061238y3916ec41l3df655b1ef8c3450@mail.gmail.com> (raw)
In-Reply-To: <20091106195914.GD89052@dan.emsphone.com>

2009/11/6 Dan Nelson <dnelson@allantgroup.com>:
> In the last episode (Nov 06), Stefano Lattarini said:
>> 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.
>>
>> Here are some minimal examples exposing the problem:
>>
>>   $ cat main2.zsh
>>   . ./inc2.zsh
>>   echo 0="$0"'
>>   echo v="$v"
>>
>>   $ cat inc2.zsh
>>   0=x
>>   v=$0
>>
>>   $ zsh main2.zsh; echo e=$?  # this causes zsh to crash
>>   *** glibc detected *** zsh: double free or corruption (!prev): 0x08d91a18 ***
>
> Here's valgrind output on a FreeBSD box:
>
> 0=main2.zsh
> v=x

Are you sure? I get
2:4: unmatched '

If you modify the script you should say so. That said, I get the crash
both with and without the extraneous quote, and your output with the
quote removed. If you get that output with it left, something is
really really strange though.

With MALLOC_CHECK_ set to show errors, I get the slightly more useful
*** glibc detected *** zsh: free(): invalid pointer: 0x08102c90 ***
(than the "double free or corruption")
With MALLOC_CHECK_ set to ignore errors, I get the output as under valgrind.

My valgrind output has line numbers so I'll include it too.

==1260== Invalid read of size 1
==1260==    at 0x8063D84: bin_dot (builtin.c:4771)
==1260==    by 0x8055D9F: execbuiltin (builtin.c:439)
==1260==    by 0x8070836: execcmd (exec.c:3104)
==1260==    by 0x806C4CB: execpline2 (exec.c:1579)
==1260==    by 0x806B8DD: execpline (exec.c:1364)
==1260==    by 0x806B14B: execlist (exec.c:1161)
==1260==    by 0x806ABE2: execode (exec.c:988)
==1260==    by 0x8084761: loop (init.c:185)
==1260==    by 0x8087322: zsh_main (init.c:1454)
==1260==    by 0x80553D5: main (main.c:93)
==1260==  Address 0x40a5fb9 is 1 bytes inside a block of size 11 free'd
==1260==    at 0x40071EA: free (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1260==    by 0x8098BBB: zsfree (mem.c:1508)
==1260==    by 0x80A809C: strvarsetfn (params.c:3215)
==1260==    by 0x80A535B: setstrvalue (params.c:2227)
==1260==    by 0x80A686D: assignsparam (params.c:2647)
==1260==    by 0x806D85A: addvars (exec.c:2136)
==1260==    by 0x806ACBD: execsimple (exec.c:1015)
==1260==    by 0x806B00E: execlist (exec.c:1129)
==1260==    by 0x806ABE2: execode (exec.c:988)
==1260==    by 0x8084761: loop (init.c:185)
==1260==    by 0x8086630: source (init.c:1156)
==1260==    by 0x8063D6E: bin_dot (builtin.c:4768)
==1260==
==1260== Invalid free() / delete / delete[]
==1260==    at 0x40071EA: free (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1260==    by 0x8098BBB: zsfree (mem.c:1508)
==1260==    by 0x8063EFE: bin_dot (builtin.c:4801)
==1260==    by 0x8055D9F: execbuiltin (builtin.c:439)
==1260==    by 0x8070836: execcmd (exec.c:3104)
==1260==    by 0x806C4CB: execpline2 (exec.c:1579)
==1260==    by 0x806B8DD: execpline (exec.c:1364)
==1260==    by 0x806B14B: execlist (exec.c:1161)
==1260==    by 0x806ABE2: execode (exec.c:988)
==1260==    by 0x8084761: loop (init.c:185)
==1260==    by 0x8087322: zsh_main (init.c:1454)
==1260==    by 0x80553D5: main (main.c:93)
==1260==  Address 0x40a5fb8 is 0 bytes inside a block of size 11 free'd
==1260==    at 0x40071EA: free (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1260==    by 0x8098BBB: zsfree (mem.c:1508)
==1260==    by 0x80A809C: strvarsetfn (params.c:3215)
==1260==    by 0x80A535B: setstrvalue (params.c:2227)
==1260==    by 0x80A686D: assignsparam (params.c:2647)
==1260==    by 0x806D85A: addvars (exec.c:2136)
==1260==    by 0x806ACBD: execsimple (exec.c:1015)
==1260==    by 0x806B00E: execlist (exec.c:1129)
==1260==    by 0x806ABE2: execode (exec.c:988)
==1260==    by 0x8084761: loop (init.c:185)
==1260==    by 0x8086630: source (init.c:1156)
==1260==    by 0x8063D6E: bin_dot (builtin.c:4768)
==1260==
2:4: unmatched '

line 4771 for that invalid read is
ret = source(arg0);
and line 4768 is
else if (arg0[1] == '.' && arg0 + 2 == s)

(Doesn't it seem like valgrind confused these two? Or am I really
stupid? 4771 is the one calling source, yet the backtrace says it is
called by 4768. I don't think I changed that file since compiling last
time, but maybe I have.)

-- 
Mikael Magnusson


  reply	other threads:[~2009-11-06 20:38 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 [this message]
2009-11-08 12:05     ` Stefano Lattarini
2009-11-06 21:30 ` Peter Stephenson

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=237967ef0911061238y3916ec41l3df655b1ef8c3450@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=dnelson@allantgroup.com \
    --cc=stefano.lattarini@gmail.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).