zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "VAN VLIERBERGHE Stef" <stef.van-vlierberghe@eurocontrol.int>,
	<zsh-workers@zsh.org>
Cc: "Genot, Harry" <harry.genot@hp.com>,
	"BOVEN Tom" <tom.boven@eurocontrol.int>,
	"LORANG Geert" <geert.lorang@eurocontrol.int>,
	"VAN DE VOORDE Bart" <bart.van-de-voorde@eurocontrol.int>,
	"Bart van den Heuvel" <bvandenh@redhat.com>,
	"CFMU HP Verbeke K" <koen.verbeke@hp.com>,
	"Godts, Jeroen" <godts@hp.com>,
	"BRENTA Ludovic" <ludovic.brenta@eurocontrol.int>,
	"WAROQUIERS Philippe" <philippe.waroquiers@eurocontrol.int>,
	"MEERSMAN Koen" <koen.meersman@eurocontrol.int>,
	"FERNANDEZ Roberto" <roberto.fernandez@eurocontrol.int>,
	"WILLEMS Eric" <eric.willems@eurocontrol.int>,
	"MAES Stefan" <stefan.maes@eurocontrol.int>,
	"THIAVILLE Eric" <eric.thiaville@eurocontrol.int>,
	"BESSIERES Marc" <marc.bessieres@eurocontrol.int>
Subject: Re: zsh-4.2.6-5.el5 rhel5.5 accesses uninitialized memory in an assignment statement using a variable name of 31 or more characters.
Date: Sat, 3 Dec 2011 17:13:04 +0000	[thread overview]
Message-ID: <20111203171304.6ab684bd@pws-pc.ntlworld.com> (raw)
In-Reply-To: <1B2B2EF98D55CB41BD16F13B18B9B008134CC157@FFBRUE001.cfmu.corp.eurocontrol.int>

On Fri, 2 Dec 2011 22:54:34 +0100
"VAN VLIERBERGHE Stef" <stef.van-vlierberghe@eurocontrol.int> wrote:
> A more conservative workaround would be to only set the memory
> extension to zero immediately after the hrealloc call, getting
> something like a hrecalloc effect, this is much less likely to trigger
> other side-effects :
> 
> After:
> 	bptr = len + (tokstr = (char *)hrealloc(tokstr, bsiz, newbsiz));
> Add:
>       memset (bptr, 0, newbsiz - bsiz); /* len == bsiz, bptr points at first re-allocated byte, newbsiz - bsiz is size added */

This looks a safe and robust fix, and isn't obviously inefficient given
that the original allocation is doing the equivalent clearing of memory.
I'll apply the following patch to the current head (post 4.3.13) (it
also deletes some cruft there's no need to propagate).

Thanks.

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.68
diff -p -u -r1.68 lex.c
--- Src/lex.c	15 Sep 2011 14:04:51 -0000	1.68
+++ Src/lex.c	3 Dec 2011 17:09:58 -0000
@@ -567,22 +567,14 @@ add(int c)
 {
     *bptr++ = c;
     if (bsiz == ++len) {
-#if 0
-	int newbsiz;
-
-	newbsiz = bsiz * 8;
-	while (newbsiz < inbufct)
-	    newbsiz *= 2;
-	bptr = len + (tokstr = (char *)hrealloc(tokstr, bsiz, newbsiz));
-	bsiz = newbsiz;
-#endif
-
 	int newbsiz = bsiz * 2;
 
 	if (newbsiz > inbufct && inbufct > bsiz)
 	    newbsiz = inbufct;
 
 	bptr = len + (tokstr = (char *)hrealloc(tokstr, bsiz, newbsiz));
+	/* len == bsiz, so bptr is at the start of newly allocated memory */
+	memset(bptr, 0, newbsiz - bsiz);
 	bsiz = newbsiz;
     }
 }


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2011-12-03 17:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <F8EF4D5D00775645B06F3DF4E25896D37E2972B582@GVW1118EXC.americas.hpqcorp.net>
     [not found] ` <A57EAE15146C184AA33F0DBEB2F830231D54E6D4@G4W3213.americas.hpqcorp.net>
2011-12-02 21:54   ` VAN VLIERBERGHE Stef
2011-12-03 17:13     ` Peter Stephenson [this message]
2011-12-03 21:21     ` uninitialized memory " Bart Schaefer
2011-12-05 20:17       ` VAN VLIERBERGHE Stef
2011-12-06  9:42         ` 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=20111203171304.6ab684bd@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=bart.van-de-voorde@eurocontrol.int \
    --cc=bvandenh@redhat.com \
    --cc=eric.thiaville@eurocontrol.int \
    --cc=eric.willems@eurocontrol.int \
    --cc=geert.lorang@eurocontrol.int \
    --cc=godts@hp.com \
    --cc=harry.genot@hp.com \
    --cc=koen.meersman@eurocontrol.int \
    --cc=koen.verbeke@hp.com \
    --cc=ludovic.brenta@eurocontrol.int \
    --cc=marc.bessieres@eurocontrol.int \
    --cc=philippe.waroquiers@eurocontrol.int \
    --cc=roberto.fernandez@eurocontrol.int \
    --cc=stef.van-vlierberghe@eurocontrol.int \
    --cc=stefan.maes@eurocontrol.int \
    --cc=tom.boven@eurocontrol.int \
    --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).