Merge pull request #249 from robertbaldyga/fix-env_strncpy-null-terminate

env: Ensure that env_strncpy() always produces NULL-terminated string
This commit is contained in:
Jan Musiał 2019-08-29 09:48:07 +02:00 committed by GitHub
commit 447333ea13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

3
env/posix/ocf_env.h vendored
View File

@ -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; \
})