From: Anatoly Burakov Date: Tue, 17 Apr 2018 14:20:45 +0000 (+0100) Subject: malloc: replace snprintf with strlcpy X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=627e80e4f6c6c886d2c48e481575f29c05cf4807;p=dpdk.git malloc: replace snprintf with strlcpy Signed-off-by: Anatoly Burakov Acked-by: Harry van Haaren --- diff --git a/lib/librte_eal/common/malloc_mp.c b/lib/librte_eal/common/malloc_mp.c index 72b1f4cb34..931c14bc5c 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();