DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] test: fix sprintf with snprintf
@ 2019-02-08 13:27 Pallantla Poornima
  2019-02-08 14:04 ` Bruce Richardson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Pallantla Poornima @ 2019-02-08 13:27 UTC (permalink / raw)
  To: dev; +Cc: reshma.pattan, ferruh.yigit, Pallantla Poornima, stable

sprintf function is not secure as it doesn't check the length of string.
More secure function snprintf is used.

Fixes: 727909c592 ("app/test: introduce dynamic commands list")
Cc: stable@dpdk.org

Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
---
 test/test/commands.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/test/test/commands.c b/test/test/commands.c
index 94fbc310e..5aeb35498 100644
--- a/test/test/commands.c
+++ b/test/test/commands.c
@@ -367,6 +367,8 @@ int commands_init(void)
 	struct test_command *t;
 	char *commands, *ptr;
 	int commands_len = 0;
+	int total_written = 0;
+	int count = 0;
 
 	TAILQ_FOREACH(t, &commands_list, next) {
 		commands_len += strlen(t->command) + 1;
@@ -378,7 +380,10 @@ int commands_init(void)
 
 	ptr = commands;
 	TAILQ_FOREACH(t, &commands_list, next) {
-		ptr += sprintf(ptr, "%s#", t->command);
+		count = snprintf(ptr, commands_len - total_written - 1, "%s#",
+				t->command);
+		ptr += count;
+		total_written += count;
 	}
 	ptr--;
 	ptr[0] = '\0';
-- 
2.17.2

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

end of thread, other threads:[~2019-02-08 17:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-08 13:27 [dpdk-dev] [PATCH] test: fix sprintf with snprintf Pallantla Poornima
2019-02-08 14:04 ` Bruce Richardson
2019-02-08 16:21 ` Stephen Hemminger
2019-02-08 17:04 ` Aaron Conole
2019-02-08 17:35   ` Stephen Hemminger

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