From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net
Subject: [dpdk-dev] [PATCH v2 1/3] malloc: replace snprintf with strlcpy
Date: Wed, 25 Apr 2018 11:15:37 +0100 [thread overview]
Message-ID: <3e6ed6d002032eebf00a73fccdd93af6769efc88.1524651111.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1524651111.git.anatoly.burakov@intel.com>
In-Reply-To: <cover.1524651111.git.anatoly.burakov@intel.com>
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/librte_eal/common/malloc_mp.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/lib/librte_eal/common/malloc_mp.c b/lib/librte_eal/common/malloc_mp.c
index 72b1f4c..931c14b 100644
--- a/lib/librte_eal/common/malloc_mp.c
+++ b/lib/librte_eal/common/malloc_mp.c
@@ -7,6 +7,7 @@
#include <rte_alarm.h>
#include <rte_errno.h>
+#include <rte_string_fns.h>
#include "eal_memalloc.h"
@@ -159,7 +160,7 @@ handle_sync(const struct rte_mp_msg *msg, const void *peer)
memset(&reply, 0, sizeof(reply));
reply.num_fds = 0;
- snprintf(reply.name, sizeof(reply.name), "%s", msg->name);
+ strlcpy(reply.name, msg->name, sizeof(reply.name));
reply.len_param = sizeof(*resp);
ret = eal_memalloc_sync_with_primary();
@@ -274,8 +275,8 @@ handle_request(const struct rte_mp_msg *msg, const void *peer __rte_unused)
/* send failure message straight away */
resp_msg.num_fds = 0;
resp_msg.len_param = sizeof(*resp);
- snprintf(resp_msg.name, sizeof(resp_msg.name), "%s",
- MP_ACTION_RESPONSE);
+ strlcpy(resp_msg.name, MP_ACTION_RESPONSE,
+ sizeof(resp_msg.name));
resp->t = m->t;
resp->result = REQ_RESULT_FAIL;
@@ -298,8 +299,7 @@ handle_request(const struct rte_mp_msg *msg, const void *peer __rte_unused)
/* we can do something, so send sync request asynchronously */
sr_msg.num_fds = 0;
sr_msg.len_param = sizeof(*sr);
- snprintf(sr_msg.name, sizeof(sr_msg.name), "%s",
- MP_ACTION_SYNC);
+ strlcpy(sr_msg.name, MP_ACTION_SYNC, sizeof(sr_msg.name));
ts.tv_nsec = 0;
ts.tv_sec = MP_TIMEOUT_S;
@@ -393,7 +393,7 @@ handle_sync_response(const struct rte_mp_msg *request,
resp->id = entry->user_req.id;
msg.num_fds = 0;
msg.len_param = sizeof(*resp);
- snprintf(msg.name, sizeof(msg.name), "%s", MP_ACTION_RESPONSE);
+ strlcpy(msg.name, MP_ACTION_RESPONSE, sizeof(msg.name));
if (rte_mp_sendmsg(&msg))
RTE_LOG(ERR, EAL, "Could not send message to secondary process\n");
@@ -417,7 +417,7 @@ handle_sync_response(const struct rte_mp_msg *request,
resp->id = entry->user_req.id;
msg.num_fds = 0;
msg.len_param = sizeof(*resp);
- snprintf(msg.name, sizeof(msg.name), "%s", MP_ACTION_RESPONSE);
+ strlcpy(msg.name, MP_ACTION_RESPONSE, sizeof(msg.name));
if (rte_mp_sendmsg(&msg))
RTE_LOG(ERR, EAL, "Could not send message to secondary process\n");
@@ -444,8 +444,7 @@ handle_sync_response(const struct rte_mp_msg *request,
/* send rollback request */
rb_msg.num_fds = 0;
rb_msg.len_param = sizeof(*rb);
- snprintf(rb_msg.name, sizeof(rb_msg.name), "%s",
- MP_ACTION_ROLLBACK);
+ strlcpy(rb_msg.name, MP_ACTION_ROLLBACK, sizeof(rb_msg.name));
ts.tv_nsec = 0;
ts.tv_sec = MP_TIMEOUT_S;
@@ -515,7 +514,7 @@ handle_rollback_response(const struct rte_mp_msg *request,
resp->id = mpreq->id;
msg.num_fds = 0;
msg.len_param = sizeof(*resp);
- snprintf(msg.name, sizeof(msg.name), "%s", MP_ACTION_RESPONSE);
+ strlcpy(msg.name, MP_ACTION_RESPONSE, sizeof(msg.name));
if (rte_mp_sendmsg(&msg))
RTE_LOG(ERR, EAL, "Could not send message to secondary process\n");
@@ -577,7 +576,7 @@ request_sync(void)
msg.num_fds = 0;
msg.len_param = sizeof(*req);
- snprintf(msg.name, sizeof(msg.name), "%s", MP_ACTION_SYNC);
+ strlcpy(msg.name, MP_ACTION_SYNC, sizeof(msg.name));
/* sync request carries no data */
req->t = REQ_TYPE_SYNC;
@@ -668,7 +667,7 @@ request_to_primary(struct malloc_mp_req *user_req)
msg.num_fds = 0;
msg.len_param = sizeof(*msg_req);
- snprintf(msg.name, sizeof(msg.name), "%s", MP_ACTION_REQUEST);
+ strlcpy(msg.name, MP_ACTION_REQUEST, sizeof(msg.name));
/* (attempt to) get a unique id */
user_req->id = get_unique_id();
--
2.7.4
next prev parent reply other threads:[~2018-04-25 10:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-17 15:48 [dpdk-dev] [PATCH 0/5] Coverity fixes for malloc Anatoly Burakov
2018-04-17 15:48 ` [dpdk-dev] [PATCH 1/5] malloc: replace snprintf with strlcpy Anatoly Burakov
2018-04-17 15:48 ` [dpdk-dev] [PATCH 2/5] malloc: fix potential out-of-bounds array access Anatoly Burakov
2018-04-17 15:48 ` [dpdk-dev] [PATCH 3/5] malloc: fix potential negative return Anatoly Burakov
2018-04-17 15:48 ` [dpdk-dev] [PATCH 4/5] malloc: fix potential dereferencing of NULL pointer Anatoly Burakov
2018-04-17 15:48 ` [dpdk-dev] [PATCH 5/5] malloc: fix potential negative return Anatoly Burakov
2018-04-25 8:24 ` Tan, Jianfeng
2018-04-25 8:50 ` Burakov, Anatoly
2018-04-25 10:15 ` [dpdk-dev] [PATCH v2 0/3] Coverity fixes for malloc Anatoly Burakov
2018-04-27 21:33 ` Thomas Monjalon
2018-04-25 10:15 ` Anatoly Burakov [this message]
2018-04-27 15:57 ` [dpdk-dev] [PATCH v2 1/3] malloc: replace snprintf with strlcpy Van Haaren, Harry
2018-04-25 10:15 ` [dpdk-dev] [PATCH v2 2/3] malloc: fix potential out-of-bounds array access Anatoly Burakov
2018-04-27 15:57 ` Van Haaren, Harry
2018-04-25 10:15 ` [dpdk-dev] [PATCH v2 3/3] malloc: fix potential dereferencing of NULL pointer Anatoly Burakov
2018-04-27 15:57 ` Van Haaren, Harry
2018-04-27 16:02 ` Burakov, Anatoly
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=3e6ed6d002032eebf00a73fccdd93af6769efc88.1524651111.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
/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).