zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] Fix buffer overflow in mindist.
Date: Wed, 5 Jan 2011 17:20:29 +0000	[thread overview]
Message-ID: <20110105172029.0b2e1de6@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20101227120023.GA27174@alpha.rzhou.org>

On Mon, 27 Dec 2010 07:00:23 -0500
Ricky Zhou <ricky@rzhou.org> wrote:
> (reported at https://bugzilla.redhat.com/show_bug.cgi?id=591377)

Reports there are no use to us and we are emphatically *not* in the
position to look at more sources of information, is anyone passing them
on?

> +
> +    /* input was too long and result got truncated */
> +    len = snprintf(buf, sizeof(buf), "%s/%s", dir, mindistguess);
> +    if (len >= sizeof(buf) || len < 0) {
> +        return mindistd;
> +    }
> +

Thanks, we might as well fix the problem robustly since buf is only
needed locally.  (Robustly except for the fact the shell crashes
horribly if it runs out of memory, but there's no hope of fixing that.)

Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.252
diff -p -u -r1.252 utils.c
--- Src/utils.c	20 Dec 2010 10:28:43 -0000	1.252
+++ Src/utils.c	5 Jan 2011 17:15:08 -0000
@@ -3667,16 +3667,22 @@ mindist(char *dir, char *mindistguess, c
     int mindistd, nd;
     DIR *dd;
     char *fn;
-    char buf[PATH_MAX];
+    char *buf;
 
     if (dir[0] == '\0')
 	dir = ".";
     mindistd = 100;
+
+    buf = zalloc(strlen(dir) + strlen(mindistguess) + 2);
     sprintf(buf, "%s/%s", dir, mindistguess);
+
     if (access(unmeta(buf), F_OK) == 0) {
 	strcpy(mindistbest, mindistguess);
+	free(buf);
 	return 0;
     }
+    free(buf);
+
     if (!(dd = opendir(unmeta(dir))))
 	return mindistd;
     while ((fn = zreaddir(dd, 0))) {

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


  reply	other threads:[~2011-01-05 17:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-27 12:00 Ricky Zhou
2011-01-05 17:20 ` Peter Stephenson [this message]
2011-01-05 18:33   ` Ricky Zhou

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=20110105172029.0b2e1de6@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).