Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh 4.3.13 released



On Sat, Dec 03, 2011 at 10:56:10PM +0000, Peter Stephenson wrote:
> On Sat, 3 Dec 2011 23:19:54 +0100
> ports@xxxxxxxxxxxx wrote:
> > % zmodload -i bogus/notamodule
> > Segmentation fault (core dumped)
> >....
> > #0  0x000000000048f5bc in metafy (buf=0x207a096d7 "File not found", len=14, heap=1) at utils.c:4006
> > 4006        *e = '\0';
> > (gdb) bt
> > #0  0x000000000048f5bc in metafy (buf=0x207a096d7 "File not found", len=14, heap=1) at utils.c:4006
> 
> heap=1 is META_USEHEAP: "get memory from the heap.  This leaves buf
> unchanged."  However, the function unconditionally attempts to add nullL
> termination.  A defence lawyer could probably claim that adding a null
> when there was one already there wasn't actually modification.  Not sure
> how we've avoided seeing this before.
> 
> It seems some parts of the code are relying on the fact that the NULL
> gets added even if the string doesn't need metafying.  Treating the
> absence of NULL termination as a reason for modifying the buffer was the
> neatest of the three fixes I came up with.
> 
> Index: Src/utils.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
> retrieving revision 1.264
> diff -p -u -r1.264 utils.c
> --- Src/utils.c	15 Nov 2011 15:08:57 -0000	1.264
> +++ Src/utils.c	3 Dec 2011 22:51:19 -0000
> @@ -3959,7 +3959,7 @@ metafy(char *buf, int len, int heap)
>  	    if (imeta(*e++))
>  		meta++;
>  
> -    if (meta || heap == META_DUP || heap == META_HEAPDUP) {
> +    if (meta || heap == META_DUP || heap == META_HEAPDUP || *e != '\0') {
>  	switch (heap) {
>  	case META_REALLOC:
>  	    buf = zrealloc(buf, len + meta + 1);
> @@ -4002,8 +4002,8 @@ metafy(char *buf, int len, int heap)
>  		meta--;
>  	    }
>  	}
> +	*e = '\0';
>      }
> -    *e = '\0';
>      return buf;
>  }
>  

Works fine::
% zmodload -i bogus/notamodule
zsh: failed to load module `bogus/notamodule': File not found

Now Zsh works fine on OpenBSD. Thanks !
40 successful test scripts, 0 failures, 0 skipped

Regards,

-- 
Pierre-Emmanuel André <pea at raveland.org>
GPG key: 0x7AE329DC



Messages sorted by: Reverse Date, Date, Thread, Author