zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: utils.c: Fix use of uninitialized memory in metafy().
@ 2013-11-27 17:45 Simon Ruderich
  2013-11-27 18:07 ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Ruderich @ 2013-11-27 17:45 UTC (permalink / raw)
  To: zsh-workers

[-- 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 --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-11-28  9:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-27 17:45 PATCH: utils.c: Fix use of uninitialized memory in metafy() Simon Ruderich
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

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).