DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2] app/test: fix sprintf with strlcat
@ 2019-03-13 11:07 Pallantla Poornima
  2019-03-13 13:51 ` Aaron Conole
  0 siblings, 1 reply; 4+ messages in thread
From: Pallantla Poornima @ 2019-03-13 11:07 UTC (permalink / raw)
  To: dev
  Cc: reshma.pattan, ferruh.yigit, aconole, bruce.richardson, stephen,
	Pallantla Poornima, stable

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

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

Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
---
v2: Used strlcat to avoid buffer overflow.
---
 app/test/commands.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/app/test/commands.c b/app/test/commands.c
index 94fbc310e..8d5a03a95 100644
--- a/app/test/commands.c
+++ b/app/test/commands.c
@@ -44,6 +44,7 @@
 #include <cmdline_parse_num.h>
 #include <cmdline_parse_string.h>
 #include <cmdline.h>
+#include <rte_string_fns.h>
 
 #include "test.h"
 
@@ -365,23 +366,22 @@ cmdline_parse_ctx_t main_ctx[] = {
 int commands_init(void)
 {
 	struct test_command *t;
-	char *commands, *ptr;
+	char *commands;
 	int commands_len = 0;
 
 	TAILQ_FOREACH(t, &commands_list, next) {
 		commands_len += strlen(t->command) + 1;
 	}
 
-	commands = malloc(commands_len + 1);
+	commands = (char *)calloc(commands_len, sizeof(char));
 	if (!commands)
 		return -1;
 
-	ptr = commands;
 	TAILQ_FOREACH(t, &commands_list, next) {
-		ptr += sprintf(ptr, "%s#", t->command);
+		strlcat(commands, t->command, commands_len);
+		if (TAILQ_NEXT(t, next) != NULL)
+			strlcat(commands, "#", commands_len);
 	}
-	ptr--;
-	ptr[0] = '\0';
 
 	cmd_autotest_autotest.string_data.str = commands;
 	return 0;
-- 
2.17.2

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

* Re: [dpdk-dev] [PATCH v2] app/test: fix sprintf with strlcat
  2019-03-13 11:07 [dpdk-dev] [PATCH v2] app/test: fix sprintf with strlcat Pallantla Poornima
@ 2019-03-13 13:51 ` Aaron Conole
  2019-04-02  0:37   ` Thomas Monjalon
  0 siblings, 1 reply; 4+ messages in thread
From: Aaron Conole @ 2019-03-13 13:51 UTC (permalink / raw)
  To: Pallantla Poornima
  Cc: dev, reshma.pattan, ferruh.yigit, bruce.richardson, stephen, stable

Pallantla Poornima <pallantlax.poornima@intel.com> writes:

> sprintf function is not secure as it doesn't check the length of string.
> More secure function strlcat is used.
>
> Fixes: 727909c592 ("app/test: introduce dynamic commands list")
> Cc: stable@dpdk.org
>
> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
> ---
> v2: Used strlcat to avoid buffer overflow.
> ---

LGTM.

Reviewed-by: Aaron Conole <aconole@redhat.com>

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

* Re: [dpdk-dev] [PATCH v2] app/test: fix sprintf with strlcat
  2019-03-13 13:51 ` Aaron Conole
@ 2019-04-02  0:37   ` Thomas Monjalon
  2019-04-02  0:37     ` Thomas Monjalon
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Monjalon @ 2019-04-02  0:37 UTC (permalink / raw)
  To: Pallantla Poornima
  Cc: dev, Aaron Conole, reshma.pattan, ferruh.yigit, bruce.richardson,
	stephen, stable

13/03/2019 14:51, Aaron Conole:
> Pallantla Poornima <pallantlax.poornima@intel.com> writes:
> 
> > sprintf function is not secure as it doesn't check the length of string.
> > More secure function strlcat is used.
> >
> > Fixes: 727909c592 ("app/test: introduce dynamic commands list")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
> > ---
> > v2: Used strlcat to avoid buffer overflow.
> > ---
> 
> LGTM.
> 
> Reviewed-by: Aaron Conole <aconole@redhat.com>

Applied, thanks

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

* Re: [dpdk-dev] [PATCH v2] app/test: fix sprintf with strlcat
  2019-04-02  0:37   ` Thomas Monjalon
@ 2019-04-02  0:37     ` Thomas Monjalon
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2019-04-02  0:37 UTC (permalink / raw)
  To: Pallantla Poornima
  Cc: dev, Aaron Conole, reshma.pattan, ferruh.yigit, bruce.richardson,
	stephen, stable

13/03/2019 14:51, Aaron Conole:
> Pallantla Poornima <pallantlax.poornima@intel.com> writes:
> 
> > sprintf function is not secure as it doesn't check the length of string.
> > More secure function strlcat is used.
> >
> > Fixes: 727909c592 ("app/test: introduce dynamic commands list")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
> > ---
> > v2: Used strlcat to avoid buffer overflow.
> > ---
> 
> LGTM.
> 
> Reviewed-by: Aaron Conole <aconole@redhat.com>

Applied, thanks



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

end of thread, other threads:[~2019-04-02  0:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-13 11:07 [dpdk-dev] [PATCH v2] app/test: fix sprintf with strlcat Pallantla Poornima
2019-03-13 13:51 ` Aaron Conole
2019-04-02  0:37   ` Thomas Monjalon
2019-04-02  0:37     ` Thomas Monjalon

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