zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Complex config triggering Segfault in pattern matching code.
Date: Thu, 18 Dec 2014 19:09:24 +0000	[thread overview]
Message-ID: <20141218190924.0f08548b@pws-pc.ntlworld.com> (raw)
In-Reply-To: <141217221400.ZM13648@torch.brasslantern.com>

On Wed, 17 Dec 2014 22:14:00 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> This is the one that repeats a lot:
> 
> ==1705==  Uninitialised value was created by a heap allocation
> ==1705==    at 0x4C2C29E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1705==    by 0x45C798: zrealloc (mem.c:938)
> ==1705==    by 0x65B0D18: set_region_highlight (zle_refresh.c:454)
> 
> It would appear that the loop at zle_refresh.c:461 needs to assign
> values to rhp->start_meta and rhp->end_meta at the same time that it
> calculates rhp->start and rhp->end.  However, I'm not familiar enough
> with the region_highlight algorithm to be sure how to initialize those.

Zeroing at the realloc should stop this.  Watch carefully in case I've
got the sums wrong.
 
> It's possible that fixing this will fix the next one as a side-effect.
> 
> Finally this one repeats a few times:
> 
> ==1705== Conditional jump or move depends on uninitialised value(s)
> ==1705==    at 0x5A04253: vfprintf (in /usr/lib/libc-2.20.so)
> ==1705==    by 0x5A278FA: vsprintf (in /usr/lib/libc-2.20.so)
> ==1705==    by 0x5A0ACD6: sprintf (in /usr/lib/libc-2.20.so)
> ==1705==    by 0x65B0B66: get_region_highlight (zle_refresh.c:410)
> 
> That's this:
> 
> 	sprintf(digbuf1, "%d", rhp->start);
> 	sprintf(digbuf2, "%d", rhp->end);
> 
> I'm confused about that one because I can't see where rhp->start might
> be coming from without getting initialized.  It LOOKS like the loop in
> set_region_highlight() always either initializes those, or truncates
> the array to be no more than N_SPECIAL_HIGHLIGHTS elements long.  In
> the latter case the loop containing those sprintf's should never make
> a circuit.  There is a potential problem in that the loop test is just
> (arrsize--) which could go on infinitely if arrsize is negative when
> the loop begins, but there isn't enough log output for this to be an
> infinite loop.

I don't see how arrsize could be negative, but here's a debug test.

diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 9f80753..d63f9b8 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -399,6 +399,7 @@ get_region_highlight(UNUSED(Param pm))
     if (!arrsize)
 	return hmkarray(NULL);
     arrsize -= N_SPECIAL_HIGHLIGHTS;
+    DPUTS(arrsize < 0, "arrsize is negative from n_region_highlights");
     arrp = retarr = (char **)zhalloc((arrsize+1)*sizeof(char *));
 
     /* ignore special highlighting */
@@ -450,10 +451,15 @@ set_region_highlight(UNUSED(Param pm), char **aval)
     len = aval ? arrlen(aval) : 0;
     if (n_region_highlights != len + N_SPECIAL_HIGHLIGHTS) {
 	/* no null termination, but include special highlighting at start */
-	n_region_highlights = len + N_SPECIAL_HIGHLIGHTS;
+	int newsize = len + N_SPECIAL_HIGHLIGHTS
+	int diffsize = newsize - n_region_highlights;
 	region_highlights = (struct region_highlight *)
 	    zrealloc(region_highlights,
-		     sizeof(struct region_highlight) * n_region_highlights);
+		     sizeof(struct region_highlight) * newsize);
+	if (diffsize > 0)
+	    memset(region_highlights + newsize, 0,
+		   sizeof(struct region_highlight) * diffsize);
+	n_region_highlights = newsize;
     }
 
     if (!aval)

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


  reply	other threads:[~2014-12-18 19:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-13 19:49 Jonathan H
2014-12-13 23:28 ` Bart Schaefer
2014-12-13 23:36   ` Jonathan H
2014-12-14  4:40     ` Bart Schaefer
2014-12-14 18:20       ` Peter Stephenson
2014-12-14 18:43         ` Bart Schaefer
2014-12-15 21:20         ` Jonathan H
2014-12-15 23:39           ` Bart Schaefer
2014-12-16 20:58             ` Peter Stephenson
2014-12-17 17:18             ` Jonathan H
2014-12-18  6:14               ` Bart Schaefer
2014-12-18 19:09                 ` Peter Stephenson [this message]
2014-12-18 19:34                   ` Peter Stephenson
2014-12-29  0:57                   ` Daniel Shahaf

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=20141218190924.0f08548b@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).