From 8d02d5a5aa23b3260cd4e83569ad9ee09bb73ff7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 21:24:31 +0100 Subject: [PATCH] never use strncpy, anywhere. --- src/bind_config.c | 3 ++- src/helpers.c | 2 +- src/util/log.test.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bind_config.c b/src/bind_config.c index 3959cc22c..929e4cca0 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ int config_parse(const char *json) if (xp >= ep) break; } xp = (ep > json + 10) ? ep - 10 : json; - strncpy(buffer, xp, sizeof(buffer)); + strlcpy(buffer, xp, sizeof(buffer)); buffer[9] = 0; log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer); } diff --git a/src/helpers.c b/src/helpers.c index aa9bc12eb..e9502e075 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -167,7 +167,7 @@ static int lua_callspell(castorder * co) if (hashpos != NULL) { ptrdiff_t len = hashpos - fname; assert(len < (ptrdiff_t) sizeof(fbuf)); - strncpy(fbuf, fname, len); + memcpy(fbuf, fname, len); fbuf[len] = '\0'; fname = fbuf; } diff --git a/src/util/log.test.c b/src/util/log.test.c index 95cbefa96..55616c026 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -12,7 +12,7 @@ void log_string(void *data, int level, const char *module, const char *format, v unused_arg(format); unused_arg(module); unused_arg(level); - strncpy(str, arg, 32); + strcpy(str, arg); } static void test_logging(CuTest * tc)