Skip to contentSkip to conversation

hexdump: fix segfault due to uninitialized memory

PATCH Applied Petr Uzel 2 participants 2 messages Aug 10, 2011 – Aug 15, 2011 Util-Linux package

lore
Share & tools
lore

Petr Uzel

author
#0 lore raw

PATCH 1/1 hexdump: fix segfault due to uninitialized memory

util-linux commit 85bf44b714ab184907eb448eba389218956d6a51 replaced all calls to emalloc() with xmalloc(), whose semantics is however different - it does not zero allocated memory. This made hexdump segfault if MALLOC_PERTURB_ was set.

Addresses: https://bugzilla.novell.com/show_bug.cgi?id=710877

---
 text-utils/display.c |    4 ++--
 text-utils/parse.c   |    6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
text-utils/display.c +2 -2
index c700b02..ad638e7 100644
@@ -233,8 +233,8 @@ get(void)
 	u_char *tmpp;
 
 	if (!curp) {
-		curp = xmalloc(blocksize);
-		savp = xmalloc(blocksize);
+		curp = xcalloc(1, blocksize);
+		savp = xcalloc(1, blocksize);
 	} else {
 		tmpp = curp;
 		curp = savp;
text-utils/parse.c +3 -3
index 7168aad..e41b4a0 100644
@@ -86,7 +86,7 @@ void add(const char *fmt)
 	const char *savep;
 
 	/* Start new linked list of format units. */
-	tfs = xmalloc(sizeof(FS));
+	tfs = xcalloc(1, sizeof(FS));
 	if (!fshead)
 		fshead = tfs;
 	else
@@ -102,7 +102,7 @@ void add(const char *fmt)
 			break;
 
 		/* Allocate a new format unit and link it in. */
-		tfu = xmalloc(sizeof(FU));
+		tfu = xcalloc(1, sizeof(FU));
 		*nextfu = tfu;
 		nextfu = &tfu->nextfu;
 		tfu->reps = 1;
@@ -219,7 +219,7 @@ void rewrite(FS *fs)
 		 * conversion character gets its own.
 		 */
 		for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
-			pr = xmalloc(sizeof(PR));
+			pr = xcalloc(1, sizeof(PR));
 			if (!fu->nextpr)
 				fu->nextpr = pr;
 			else
Signature · 8 lines
1.7.3.4


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode
maintainer Applied
#1 lore raw
Quoted 3 lines · Petr Uzel
 text-utils/display.c |    4 ++--
 text-utils/parse.c   |    6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com