[dpdk-dev] Fix buffer overflow issue in app/test/commands.c(we add 1 extra byte for trailing \0).

Message ID 1456470671-18425-1-git-send-email-mzhao@luminatewireless.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Ming Zhao Feb. 26, 2016, 7:11 a.m. UTC
  Fix memleak of cmdline in app/test/test.c
---
 app/test/commands.c | 2 +-
 app/test/test.c     | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
  

Comments

Thomas Monjalon March 5, 2016, 10:09 p.m. UTC | #1
Hi,

2016-02-25 23:11, Ming Zhao:
> Fix memleak of cmdline in app/test/test.c

It looks to be two different fixes:
- an overflow
- a memleak

Please send 2 patches,
with Fixes lines (even if is there since the first commit),
with Signed-off-by line.
See http://dpdk.org/doc/guides/contributing/patches.html#commit-messages-subject-line
  

Patch

diff --git a/app/test/commands.c b/app/test/commands.c
index 9cb9606..5dfa599 100644
--- a/app/test/commands.c
+++ b/app/test/commands.c
@@ -439,7 +439,7 @@  int commands_init(void)
 		commands_len += strlen(t->command) + 1;
 	}
 
-	commands = malloc(commands_len);
+	commands = malloc(commands_len + 1); /* one more byte for \0 */
 	if (!commands)
 		return -1;
 
diff --git a/app/test/test.c b/app/test/test.c
index f35b304..108a347 100644
--- a/app/test/test.c
+++ b/app/test/test.c
@@ -150,6 +150,7 @@  main(int argc, char **argv)
 	}
 	cmdline_interact(cl);
 	cmdline_stdin_exit(cl);
+        cmdline_free(cl);
 #endif
 
 	return 0;