[PATCH] hexdump: don't access hex after freeing it

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Andrew Vagin <avagin@xxxxxxxxxx>

==20209== Invalid read of size 4
==20209==    at 0x923C: main (hexdump.c:202)
==20209==  Address 0x49af034 is 12 bytes inside a block of size 32 free'd
==20209==    at 0x48348B8: free (vg_replace_malloc.c:427)
==20209==    by 0x923B: main (hexdump.c:200)

Signed-off-by: Andrey Vagin <avagin@xxxxxxxxxx>
---
 text-utils/hexdump.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 1806077..cebd676 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -165,11 +165,13 @@ int main(int argc, char **argv)
 {
 	struct list_head *p;
 	struct hexdump_fs *tfs;
+	int ret;
 	char *c;
 
 	struct hexdump *hex = malloc (sizeof (struct hexdump));
 	hex->length = -1;
 	hex->skip = 0;
+	hex->exitval = 0;
 	INIT_LIST_HEAD(&hex->fshead);
 
 	setlocale(LC_ALL, "");
@@ -197,8 +199,9 @@ int main(int argc, char **argv)
 
 	next(argv, hex);
 	display(hex);
+	ret = hex->exitval;
 	hex_free(hex);
-	return hex->exitval;
+	return ret;
 }
 
 void hex_free(struct hexdump *hex)
-- 
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux