From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 857EBCF9E for ; Tue, 17 Apr 2018 17:48:20 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Apr 2018 08:48:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,464,1517904000"; d="scan'208";a="33284079" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga008.fm.intel.com with ESMTP; 17 Apr 2018 08:48:18 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w3HFmIV7030997; Tue, 17 Apr 2018 16:48:18 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w3HFmIma024772; Tue, 17 Apr 2018 16:48:18 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w3HFmHHl024768; Tue, 17 Apr 2018 16:48:18 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net Date: Tue, 17 Apr 2018 16:48:13 +0100 Message-Id: <780e343763e4385cb54a37acc2053550164aca98.1523979264.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/5] malloc: replace snprintf with strlcpy X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Apr 2018 15:48:21 -0000 Signed-off-by: Anatoly Burakov --- 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 #include +#include #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