[dpdk-dev] app/test-crypto-perf: fix buffer not null terminated

Message ID 1486459218-11455-1-git-send-email-aleksanderx.gajewski@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Pablo de Lara Guarch
Headers

Checks

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

Commit Message

Aleksander Gajewski Feb. 7, 2017, 9:20 a.m. UTC
  Fix problem: the string buffer may not have a null terminator if
the source string's length is equal to the buffer size.

Coverity issue: 141069
Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
application")

Signed-off-by: Aleksander Gajewski <aleksanderx.gajewski@intel.com>
---
 app/test-crypto-perf/cperf_options_parsing.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

De Lara Guarch, Pablo Feb. 9, 2017, 10:41 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Aleksander
> Gajewski
> Sent: Tuesday, February 07, 2017 9:20 AM
> To: Doherty, Declan
> Cc: dev@dpdk.org; Gajewski, AleksanderX
> Subject: [dpdk-dev] [PATCH] app/test-crypto-perf: fix buffer not null
> terminated
> 
> Fix problem: the string buffer may not have a null terminator if
> the source string's length is equal to the buffer size.
> 
> Coverity issue: 141069
> Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> application")
> 
> Signed-off-by: Aleksander Gajewski <aleksanderx.gajewski@intel.com>

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
  
De Lara Guarch, Pablo Feb. 9, 2017, 11 p.m. UTC | #2
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of De Lara Guarch,
> Pablo
> Sent: Thursday, February 09, 2017 10:42 PM
> To: Gajewski, AleksanderX; Doherty, Declan
> Cc: dev@dpdk.org; Gajewski, AleksanderX
> Subject: Re: [dpdk-dev] [PATCH] app/test-crypto-perf: fix buffer not null
> terminated
> 
> 
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Aleksander
> > Gajewski
> > Sent: Tuesday, February 07, 2017 9:20 AM
> > To: Doherty, Declan
> > Cc: dev@dpdk.org; Gajewski, AleksanderX
> > Subject: [dpdk-dev] [PATCH] app/test-crypto-perf: fix buffer not null
> > terminated
> >
> > Fix problem: the string buffer may not have a null terminator if
> > the source string's length is equal to the buffer size.
> >
> > Coverity issue: 141069
> > Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> > application")
> >
> > Signed-off-by: Aleksander Gajewski <aleksanderx.gajewski@intel.com>
> 
> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Applied to dpdk-next-crypto.
Thanks,

Pablo
  

Patch

diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 3b7342d..691e788 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -198,7 +198,8 @@  struct name_id_map {
 	if (strlen(arg) > (sizeof(opts->device_type) - 1))
 		return -1;
 
-	strncpy(opts->device_type, arg, sizeof(opts->device_type));
+	strncpy(opts->device_type, arg, sizeof(opts->device_type) - 1);
+	*(opts->device_type + sizeof(opts->device_type) - 1) = '\0';
 
 	return 0;
 }