From: Pallantla Poornima <pallantlax.poornima@intel.com>
To: dev@dpdk.org
Cc: reshma.pattan@intel.com, ferruh.yigit@intel.com,
aconole@redhat.com, bruce.richardson@intel.com,
stephen@networkplumber.org,
Pallantla Poornima <pallantlax.poornima@intel.com>,
stable@dpdk.org
Subject: [dpdk-stable] [PATCH v2] app/test: fix sprintf with strlcat
Date: Wed, 13 Mar 2019 11:07:23 +0000 [thread overview]
Message-ID: <1552475243-16215-1-git-send-email-pallantlax.poornima@intel.com> (raw)
In-Reply-To: <y>
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
next reply other threads:[~2019-03-13 11:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-13 11:07 Pallantla Poornima [this message]
2019-03-13 13:51 ` Aaron Conole
2019-04-02 0:37 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1552475243-16215-1-git-send-email-pallantlax.poornima@intel.com \
--to=pallantlax.poornima@intel.com \
--cc=aconole@redhat.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=reshma.pattan@intel.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).