patches for DPDK stable branches
 help / color / Atom feed
* [dpdk-stable] [PATCH 17.11] app/proc_info: fix string copying to use strlcpy
@ 2020-01-06 11:42 Ciara Power
  2020-01-06 12:53 ` Tahhan, Maryam
  0 siblings, 1 reply; 3+ messages in thread
From: Ciara Power @ 2020-01-06 11:42 UTC (permalink / raw)
  To: stable; +Cc: maryam.tahhan, reshma.pattan, Ciara Power, romanx.korynkevych

[ upstream commit 7edbf7ddfd7d2453afaad3b72666491d30b616af ]

Replaced strncpy and strcpy with strlcpy.
Using strlcpy is safe practice when copying strings,
as it will include a null terminator.

Cc: romanx.korynkevych@intel.com

Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
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>
---
 app/proc_info/main.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 2893bec69..caf4e48c0 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -196,7 +196,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;
@@ -363,50 +363,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);
 	}
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-stable] [PATCH 17.11] app/proc_info: fix string copying to use strlcpy
  2020-01-06 11:42 [dpdk-stable] [PATCH 17.11] app/proc_info: fix string copying to use strlcpy Ciara Power
@ 2020-01-06 12:53 ` Tahhan, Maryam
  2020-01-07 11:29   ` Luca Boccassi
  0 siblings, 1 reply; 3+ messages in thread
From: Tahhan, Maryam @ 2020-01-06 12:53 UTC (permalink / raw)
  To: Power, Ciara, stable; +Cc: Pattan, Reshma, romanx.korynkevych

> [ upstream commit 7edbf7ddfd7d2453afaad3b72666491d30b616af ]
> 
> Replaced strncpy and strcpy with strlcpy.
> Using strlcpy is safe practice when copying strings, as it will include a null
> terminator.
> 
> Cc: romanx.korynkevych@intel.com
> 
> Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
> 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>
> ---
>  app/proc_info/main.c | 36 ++++++++++++++++++------------------
>  1 file changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/app/proc_info/main.c b/app/proc_info/main.c index
> 2893bec69..caf4e48c0 100644
> --- a/app/proc_info/main.c
> +++ b/app/proc_info/main.c
> @@ -196,7 +196,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;
> @@ -363,50 +363,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);
>  	}
>  }
> 
> --
> 2.17.1

Acked-by: Maryam Tahhan <maryam.tahhan@intel.com> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-stable] [PATCH 17.11] app/proc_info: fix string copying to use strlcpy
  2020-01-06 12:53 ` Tahhan, Maryam
@ 2020-01-07 11:29   ` Luca Boccassi
  0 siblings, 0 replies; 3+ messages in thread
From: Luca Boccassi @ 2020-01-07 11:29 UTC (permalink / raw)
  To: Tahhan, Maryam, Power, Ciara, stable; +Cc: Pattan, Reshma, romanx.korynkevych

On Mon, 2020-01-06 at 12:53 +0000, Tahhan, Maryam wrote:
> > [ upstream commit 7edbf7ddfd7d2453afaad3b72666491d30b616af ]
> > 
> > Replaced strncpy and strcpy with strlcpy.
> > Using strlcpy is safe practice when copying strings, as it will
> > include a null
> > terminator.
> > 
> > Cc: romanx.korynkevych@intel.com
> > 
> > Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host
> > id")
> > 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>
> > ---
> >  app/proc_info/main.c | 36 ++++++++++++++++++------------------
> >  1 file changed, 18 insertions(+), 18 deletions(-)
> > 
> > diff --git a/app/proc_info/main.c b/app/proc_info/main.c index
> > 2893bec69..caf4e48c0 100644
> > --- a/app/proc_info/main.c
> > +++ b/app/proc_info/main.c
> > @@ -196,7 +196,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;
> > @@ -363,50 +363,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);
> >  	}
> >  }
> > 
> > --
> > 2.17.1
> 
> Acked-by: Maryam Tahhan <maryam.tahhan@intel.com> 

Thanks, applied

-- 
Kind regards,
Luca Boccassi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-06 11:42 [dpdk-stable] [PATCH 17.11] app/proc_info: fix string copying to use strlcpy Ciara Power
2020-01-06 12:53 ` Tahhan, Maryam
2020-01-07 11:29   ` Luca Boccassi

patches for DPDK stable branches

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ http://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/ public-inbox