From: Quentin Young Date: Tue, 26 Feb 2019 20:25:24 +0000 (+0000) Subject: lib: strncpy -> strlcpy | memcpy X-Git-Tag: 7.1_pulled~200^2~3 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=aab9a0a0cb3f75d37bd81588c65d4232def1c8d5;p=matthieu%2Ffrr.git lib: strncpy -> strlcpy | memcpy strncpy is a byte copy function not a string copy function Signed-off-by: Quentin Young --- diff --git a/lib/event_counter.c b/lib/event_counter.c index c520937a38..57dbfb5fd1 100644 --- a/lib/event_counter.c +++ b/lib/event_counter.c @@ -62,7 +62,7 @@ const char *event_counter_format(const struct event_counter *counter) || strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %T %z", last_change) == 0) { - strncpy(timebuf, "???", sizeof(timebuf)); + strlcpy(timebuf, "???", sizeof(timebuf)); } snprintf(rv, sizeof(rv), "%5llu last: %s", counter->count, diff --git a/lib/prefix.c b/lib/prefix.c index babd4304d1..80a89cc3c7 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -866,7 +866,7 @@ int str2prefix_ipv4(const char *str, struct prefix_ipv4 *p) return ret; } else { cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1); - strncpy(cp, str, pnt - str); + memcpy(cp, str, pnt - str); *(cp + (pnt - str)) = '\0'; ret = inet_aton(cp, &p->prefix); XFREE(MTYPE_TMP, cp); @@ -913,7 +913,7 @@ int str2prefix_eth(const char *str, struct prefix_eth *p) } cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1); - strncpy(cp, str, pnt - str); + memcpy(cp, str, pnt - str); *(cp + (pnt - str)) = '\0'; str_addr = cp; @@ -1030,7 +1030,7 @@ int str2prefix_ipv6(const char *str, struct prefix_ipv6 *p) int plen; cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1); - strncpy(cp, str, pnt - str); + memcpy(cp, str, pnt - str); *(cp + (pnt - str)) = '\0'; ret = inet_pton(AF_INET6, cp, &p->prefix); XFREE(MTYPE_TMP, cp); diff --git a/lib/yang_translator.c b/lib/yang_translator.c index 6d6f92836f..76a6cc5fd1 100644 --- a/lib/yang_translator.c +++ b/lib/yang_translator.c @@ -511,7 +511,7 @@ static void str_replace(char *o_string, const char *s_string, if (!ch) return; - strncpy(buffer, o_string, ch - o_string); + memcpy(buffer, o_string, ch - o_string); buffer[ch - o_string] = 0; sprintf(buffer + (ch - o_string), "%s%s", r_string,