[dpdk-dev,v3] app/procinfo: fix strncpy count issue

Message ID 1519134742-22648-1-git-send-email-radu.nicolau@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Radu Nicolau Feb. 20, 2018, 1:52 p.m. UTC
  Replace strncpy with snprintf to avoid overwriting the last
NULL character.

Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
Coverity issue: 143252

Cc: stable@dpdk.org

Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
v3: replaced strncpy with snprintf

 app/proc_info/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Bruce Richardson Feb. 20, 2018, 2:16 p.m. UTC | #1
On Tue, Feb 20, 2018 at 01:52:22PM +0000, Radu Nicolau wrote:
> Replace strncpy with snprintf to avoid overwriting the last
> NULL character.
> 
> Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
> Coverity issue: 143252
> 
> Cc: stable@dpdk.org
> 
> Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon March 27, 2018, 10:25 p.m. UTC | #2
20/02/2018 15:16, Bruce Richardson:
> On Tue, Feb 20, 2018 at 01:52:22PM +0000, Radu Nicolau wrote:
> > Replace strncpy with snprintf to avoid overwriting the last
> > NULL character.
> > 
> > Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id")
> > Coverity issue: 143252
> > 
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
> > ---
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
  

Patch

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 2f53e3c..f90c144 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -159,7 +159,7 @@  proc_info_preparse_args(int argc, char **argv)
 				proc_info_usage(prgname);
 				return -1;
 			}
-			strncpy(host_id, argv[i+1], sizeof(host_id));
+			snprintf(host_id, sizeof(host_id), "%s", argv[i+1]);
 		}
 	}