From 74bd0e3f7be31cc97fa789989937df5a3072599c Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Wed, 28 Aug 2019 16:20:10 +0200 Subject: [PATCH] env: Ensure that env_strncpy() always produces NULL-terminated string Signed-off-by: Robert Baldyga --- env/posix/ocf_env.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/env/posix/ocf_env.h b/env/posix/ocf_env.h index 62d6e23..8baeeeb 100644 --- a/env/posix/ocf_env.h +++ b/env/posix/ocf_env.h @@ -618,7 +618,8 @@ static inline void env_sort(void *base, size_t num, size_t size, #define env_strnlen(s, smax) strnlen(s, smax) #define env_strncmp strncmp #define env_strncpy(dest, dmax, src, slen) ({ \ - strncpy(dest, src, min(dmax, slen)); \ + strncpy(dest, src, min(dmax - 1, slen)); \ + dest[dmax - 1] = '\0'; \ 0; \ })