]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hexdump: fix segfault due to uninitialized memory
authorPetr Uzel <petr.uzel@suse.cz>
Wed, 10 Aug 2011 13:32:28 +0000 (15:32 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 15 Aug 2011 12:28:21 +0000 (14:28 +0200)
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.

Reported-by: Kyrill Detinov <lazy.kent@opensuse.org>
Addresses: https://bugzilla.novell.com/show_bug.cgi?id=710877

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
text-utils/display.c
text-utils/parse.c

index c700b02791ea008f9b75f5c442721fe947183143..ad638e7f7b2914e70a56e962c512b606efba33d4 100644 (file)
@@ -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;
index 7168aadb3b239e3132ed3acdb9fb81b1d3923c2e..e41b4a0c74a2dede384ea5e913cf022cd4018fd7 100644 (file)
@@ -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