]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: remove some strcpy, strcat
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 6 May 2019 21:05:20 +0000 (21:05 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 29 May 2019 18:02:57 +0000 (18:02 +0000)
Replace with strlcpy, strlcat

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command.c
lib/libfrr.c
lib/prefix.c
lib/vty.c

index 18426e0c517eba127306834a1cd09a1d9e7413e9..29f41a712c0f9f40e19e31635a0759bfa3e122e8 100644 (file)
@@ -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);
index 5970e70a6bd493230f9b7cb5091cb963277178c5..26bdcc1a3632ab09efbc033acab79cbdd93c028b 100644 (file)
@@ -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));
 }
index d2a4c3a432351193e2c24fcb4ecb40784924ad78..42d202ddbce13dfe60321cc0b67fbb050b9f2e5a 100644 (file)
@@ -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)
index 0ee9b78b91f9afa77951178dbd734bd003396e08..91ba0a43c80594154bc20955797b8feb24a61105 100644 (file)
--- 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)