From 8ecd4048ba5d23c016df9a10225972bb78fd8044 Mon Sep 17 00:00:00 2001 From: Aleksander Gajewski Date: Tue, 7 Feb 2017 10:20:18 +0100 Subject: [PATCH] app/crypto-perf: fix string not null terminated This commit fixes the case where 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 Acked-by: Pablo de Lara --- app/test-crypto-perf/cperf_options_parsing.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index 3b7342d918..691e7889a1 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -198,7 +198,8 @@ parse_device_type(struct cperf_options *opts, const char *arg) 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; } -- 2.20.1