From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id F00224C78 for ; Wed, 25 Apr 2018 12:15:42 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Apr 2018 03:15:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,325,1520924400"; d="scan'208";a="53500449" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 25 Apr 2018 03:15:40 -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 w3PAFdoo017680; Wed, 25 Apr 2018 11:15:39 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w3PAFdIY003751; Wed, 25 Apr 2018 11:15:39 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w3PAFdJi003747; Wed, 25 Apr 2018 11:15:39 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net Date: Wed, 25 Apr 2018 11:15:37 +0100 Message-Id: <3e6ed6d002032eebf00a73fccdd93af6769efc88.1524651111.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 v2 1/3] 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: Wed, 25 Apr 2018 10:15:43 -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