From: Quentin Young Date: Mon, 6 May 2019 21:05:20 +0000 (+0000) Subject: lib: remove some strcpy, strcat X-Git-Tag: base_7.2~293^2~13 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=9f73d2c9b60e551be0229790aeb4e4224d9b2c1a;p=matthieu%2Ffrr.git lib: remove some strcpy, strcat Replace with strlcpy, strlcat Signed-off-by: Quentin Young --- diff --git a/lib/command.c b/lib/command.c index 18426e0c51..29f41a712c 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1760,10 +1760,10 @@ static int file_write_config(struct vty *vty) dirfd = open(".", O_DIRECTORY | O_RDONLY); /* if dirfd is invalid, directory sync fails, but we're still OK */ - config_file_sav = XMALLOC( - MTYPE_TMP, strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1); - strcpy(config_file_sav, config_file); - strcat(config_file_sav, CONF_BACKUP_EXT); + size_t config_file_sav_sz = strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1; + config_file_sav = XMALLOC(MTYPE_TMP, config_file_sav_sz); + strlcpy(config_file_sav, config_file, config_file_sav_sz); + strlcat(config_file_sav, CONF_BACKUP_EXT, config_file_sav_sz); config_file_tmp = XMALLOC(MTYPE_TMP, strlen(config_file) + 8); diff --git a/lib/libfrr.c b/lib/libfrr.c index 5970e70a6b..26bdcc1a36 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -80,8 +80,8 @@ static void opt_extend(const struct optspec *os) { const struct option *lo; - strcat(comb_optstr, os->optstr); - strcat(comb_helpstr, os->helpstr); + strlcat(comb_optstr, os->optstr, sizeof(comb_optstr)); + strlcat(comb_helpstr, os->helpstr, sizeof(comb_optstr)); for (lo = os->longopts; lo->name; lo++) memcpy(comb_next_lo++, lo, sizeof(*lo)); } diff --git a/lib/prefix.c b/lib/prefix.c index d2a4c3a432..42d202ddbc 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1365,7 +1365,7 @@ void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr, int save_errno = errno; if (addr.s_addr == INADDR_ANY) - strcpy(buf, "*"); + strlcpy(buf, "*", buf_size); else { if (!inet_ntop(AF_INET, &addr, buf, buf_size)) { if (onfail) diff --git a/lib/vty.c b/lib/vty.c index 0ee9b78b91..91ba0a43c8 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -1659,7 +1659,7 @@ static struct vty *vty_create(int vty_sock, union sockunion *su) /* configurable parameters not part of basic init */ vty->v_timeout = vty_timeout_val; - strcpy(vty->address, buf); + strlcpy(vty->address, buf, sizeof(vty->address)); if (no_password_check) { if (host.advanced) vty->node = ENABLE_NODE; @@ -1795,7 +1795,7 @@ struct vty *vty_stdio(void (*atclose)(int isexit)) */ vty->node = ENABLE_NODE; vty->v_timeout = 0; - strcpy(vty->address, "console"); + strlcpy(vty->address, "console", sizeof(vty->address)); vty_stdio_resume(); return vty; @@ -2384,9 +2384,10 @@ static FILE *vty_use_backup_config(const char *fullpath) int c; char buffer[512]; - fullpath_sav = malloc(strlen(fullpath) + strlen(CONF_BACKUP_EXT) + 1); - strcpy(fullpath_sav, fullpath); - strcat(fullpath_sav, CONF_BACKUP_EXT); + size_t fullpath_sav_sz = strlen(fullpath) + strlen(CONF_BACKUP_EXT) + 1; + fullpath_sav = malloc(fullpath_sav_sz); + strlcpy(fullpath_sav, fullpath, fullpath_sav_sz); + strlcat(fullpath_sav, CONF_BACKUP_EXT, fullpath_sav_sz); sav = open(fullpath_sav, O_RDONLY); if (sav < 0) { @@ -3079,8 +3080,9 @@ static void vty_save_cwd(void) } } - vty_cwd = XMALLOC(MTYPE_TMP, strlen(cwd) + 1); - strcpy(vty_cwd, cwd); + size_t vty_cwd_sz = strlen(cwd) + 1; + vty_cwd = XMALLOC(MTYPE_TMP, vty_cwd_sz); + strlcpy(vty_cwd, cwd, vty_cwd_sz); } char *vty_get_cwd(void)