* Re: [dpdk-dev] [PATCH] app/proc-info: fix string copying to use strlcpy
2019-09-26 15:11 [dpdk-dev] [PATCH] app/proc-info: fix string copying to use strlcpy Ciara Power
@ 2019-09-26 14:44 ` Bruce Richardson
2019-10-27 10:36 ` [dpdk-dev] [dpdk-stable] " David Marchand
0 siblings, 1 reply; 3+ messages in thread
From: Bruce Richardson @ 2019-09-26 14:44 UTC (permalink / raw)
To: Ciara Power; +Cc: dev, romanx.korynkevych, vipin.varghese, stable
On Thu, Sep 26, 2019 at 04:11:59PM +0100, Ciara Power wrote:
> Replaced strncpy and strcpy with strlcpy.
> Also replaced snprintf with strlcpy where applicable.
> Using strlcpy is safe practice when copying strings,
> as it will include a null terminator.
>
> Cc: romanx.korynkevych@intel.com
> Cc: vipin.varghese@intel.com
> Cc: stable@dpdk.org
>
> Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
> Fixes: 8a37f37fc243 ("app/procinfo: add --show-port")
> Reported-by: Reshma Pattan <reshma.pattan@intel.com>
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> ---
+1 for using strlcpy over strncpy
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [dpdk-dev] [PATCH] app/proc-info: fix string copying to use strlcpy
@ 2019-09-26 15:11 Ciara Power
2019-09-26 14:44 ` Bruce Richardson
0 siblings, 1 reply; 3+ messages in thread
From: Ciara Power @ 2019-09-26 15:11 UTC (permalink / raw)
To: dev; +Cc: Ciara Power, romanx.korynkevych, vipin.varghese, stable
Replaced strncpy and strcpy with strlcpy.
Also replaced snprintf with strlcpy where applicable.
Using strlcpy is safe practice when copying strings,
as it will include a null terminator.
Cc: romanx.korynkevych@intel.com
Cc: vipin.varghese@intel.com
Cc: stable@dpdk.org
Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
Fixes: 8a37f37fc243 ("app/procinfo: add --show-port")
Reported-by: Reshma Pattan <reshma.pattan@intel.com>
Signed-off-by: Ciara Power <ciara.power@intel.com>
---
app/proc-info/main.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index a89b51bb3..903921b0f 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -201,7 +201,7 @@ proc_info_preparse_args(int argc, char **argv)
int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
if (err)
- strcpy(host_id, "unknown");
+ strlcpy(host_id, "unknown", sizeof(host_id));
}
return 0;
@@ -396,50 +396,50 @@ static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
if ((type_end != NULL) &&
(strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
- strncpy(cnt_type, "if_rx_errors", cnt_type_len);
+ strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
- strncpy(cnt_type, "if_rx_dropped", cnt_type_len);
+ strlcpy(cnt_type, "if_rx_dropped", cnt_type_len);
else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
- strncpy(cnt_type, "if_rx_octets", cnt_type_len);
+ strlcpy(cnt_type, "if_rx_octets", cnt_type_len);
else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
- strncpy(cnt_type, "if_rx_packets", cnt_type_len);
+ strlcpy(cnt_type, "if_rx_packets", cnt_type_len);
else if (strncmp(type_end, "_placement",
strlen("_placement")) == 0)
- strncpy(cnt_type, "if_rx_errors", cnt_type_len);
+ strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
- strncpy(cnt_type, "if_rx_errors", cnt_type_len);
+ strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
else
/* Does not fit obvious type: use a more generic one */
- strncpy(cnt_type, "derive", cnt_type_len);
+ strlcpy(cnt_type, "derive", cnt_type_len);
} else if ((type_end != NULL) &&
(strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
- strncpy(cnt_type, "if_tx_errors", cnt_type_len);
+ strlcpy(cnt_type, "if_tx_errors", cnt_type_len);
else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
- strncpy(cnt_type, "if_tx_dropped", cnt_type_len);
+ strlcpy(cnt_type, "if_tx_dropped", cnt_type_len);
else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
- strncpy(cnt_type, "if_tx_octets", cnt_type_len);
+ strlcpy(cnt_type, "if_tx_octets", cnt_type_len);
else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
- strncpy(cnt_type, "if_tx_packets", cnt_type_len);
+ strlcpy(cnt_type, "if_tx_packets", cnt_type_len);
else
/* Does not fit obvious type: use a more generic one */
- strncpy(cnt_type, "derive", cnt_type_len);
+ strlcpy(cnt_type, "derive", cnt_type_len);
} else if ((type_end != NULL) &&
(strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
- strncpy(cnt_type, "operations", cnt_type_len);
+ strlcpy(cnt_type, "operations", cnt_type_len);
else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
- strncpy(cnt_type, "errors", cnt_type_len);
+ strlcpy(cnt_type, "errors", cnt_type_len);
else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
- strncpy(cnt_type, "filter_result", cnt_type_len);
+ strlcpy(cnt_type, "filter_result", cnt_type_len);
} else if ((type_end != NULL) &&
(strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
- strncpy(cnt_type, "errors", cnt_type_len);
+ strlcpy(cnt_type, "errors", cnt_type_len);
} else {
/* Does not fit obvious type, or strrchr error: */
/* use a more generic type */
- strncpy(cnt_type, "derive", cnt_type_len);
+ strlcpy(cnt_type, "derive", cnt_type_len);
}
}
@@ -1321,7 +1321,7 @@ main(int argc, char **argv)
if (ret)
printf("Error from rte_eal_cleanup(), %d\n", ret);
- snprintf(bdr_str, MAX_STRING_LEN, " ");
+ strlcpy(bdr_str, " ", MAX_STRING_LEN);
STATS_BDR_STR(50, bdr_str);
return 0;
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [dpdk-stable] [PATCH] app/proc-info: fix string copying to use strlcpy
2019-09-26 14:44 ` Bruce Richardson
@ 2019-10-27 10:36 ` David Marchand
0 siblings, 0 replies; 3+ messages in thread
From: David Marchand @ 2019-10-27 10:36 UTC (permalink / raw)
To: Bruce Richardson
Cc: Ciara Power, dev, romanx.korynkevych, Vipin Varghese, dpdk stable
On Thu, Sep 26, 2019 at 4:44 PM Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> On Thu, Sep 26, 2019 at 04:11:59PM +0100, Ciara Power wrote:
> > Replaced strncpy and strcpy with strlcpy.
> > Also replaced snprintf with strlcpy where applicable.
> > Using strlcpy is safe practice when copying strings,
> > as it will include a null terminator.
> >
> >
> > Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
> > Fixes: 8a37f37fc243 ("app/procinfo: add --show-port")
> > Cc: stable@dpdk.org
> > Reported-by: Reshma Pattan <reshma.pattan@intel.com>
> > Signed-off-by: Ciara Power <ciara.power@intel.com>
> > ---
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied, thanks.
--
David Marchand
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-27 10:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-26 15:11 [dpdk-dev] [PATCH] app/proc-info: fix string copying to use strlcpy Ciara Power
2019-09-26 14:44 ` Bruce Richardson
2019-10-27 10:36 ` [dpdk-dev] [dpdk-stable] " David Marchand
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).