zsh-workers
 help / color / mirror / code / Atom feed
From: Simon Ruderich <simon@ruderich.org>
To: zsh-workers@zsh.org
Subject: PATCH: utils.c: Fix use of uninitialized memory in metafy().
Date: Wed, 27 Nov 2013 18:45:16 +0100	[thread overview]
Message-ID: <bb4a5a0bb37e036855648e28ad8c663c0e0763e7.1385573927.git.simon@ruderich.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]

---
Hello,

While running the tests with valgrind I noticed an use of
uninitialized memory in metafy().

The following patch should fix it, but I don't know the details
of this code, so please check it before applying the patch.

The problem is the *e != '\0' in the next if, once e == buf +
len, *e points after buf.

Regards,
Simon

 Src/utils.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Src/utils.c b/Src/utils.c
index 0db9c30..eb71aab 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3980,10 +3980,14 @@ metafy(char *buf, int len, int heap)
 	for (e = buf, len = 0; *e; len++)
 	    if (imeta(*e++))
 		meta++;
-    } else
+    } else {
 	for (e = buf; e < buf + len;)
 	    if (imeta(*e++))
 		meta++;
+	/* go to last byte of buf */
+	if (len > 0)
+	    e--;
+    }
 
     if (meta || heap == META_DUP || heap == META_HEAPDUP || *e != '\0') {
 	switch (heap) {
-- 
1.8.4.4.12.gcc59366.dirty

-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

             reply	other threads:[~2013-11-27 17:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27 17:45 Simon Ruderich [this message]
2013-11-27 18:07 ` Peter Stephenson
2013-11-27 18:54   ` Bart Schaefer
2013-11-27 20:26     ` Peter Stephenson
2013-11-28  1:19       ` Bart Schaefer
2013-11-28  9:40         ` 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=bb4a5a0bb37e036855648e28ad8c663c0e0763e7.1385573927.git.simon@ruderich.org \
    --to=simon@ruderich.org \
    --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).