lib: remove some strcpy, strcat

Replace with strlcpy, strlcat

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2019-05-06 21:05:20 +00:00
parent 552d6491f0
commit 9f73d2c9b6
4 changed files with 16 additions and 14 deletions

View File

@ -1760,10 +1760,10 @@ static int file_write_config(struct vty *vty)
dirfd = open(".", O_DIRECTORY | O_RDONLY); dirfd = open(".", O_DIRECTORY | O_RDONLY);
/* if dirfd is invalid, directory sync fails, but we're still OK */ /* if dirfd is invalid, directory sync fails, but we're still OK */
config_file_sav = XMALLOC( size_t config_file_sav_sz = strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1;
MTYPE_TMP, strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1); config_file_sav = XMALLOC(MTYPE_TMP, config_file_sav_sz);
strcpy(config_file_sav, config_file); strlcpy(config_file_sav, config_file, config_file_sav_sz);
strcat(config_file_sav, CONF_BACKUP_EXT); strlcat(config_file_sav, CONF_BACKUP_EXT, config_file_sav_sz);
config_file_tmp = XMALLOC(MTYPE_TMP, strlen(config_file) + 8); config_file_tmp = XMALLOC(MTYPE_TMP, strlen(config_file) + 8);

View File

@ -80,8 +80,8 @@ static void opt_extend(const struct optspec *os)
{ {
const struct option *lo; const struct option *lo;
strcat(comb_optstr, os->optstr); strlcat(comb_optstr, os->optstr, sizeof(comb_optstr));
strcat(comb_helpstr, os->helpstr); strlcat(comb_helpstr, os->helpstr, sizeof(comb_optstr));
for (lo = os->longopts; lo->name; lo++) for (lo = os->longopts; lo->name; lo++)
memcpy(comb_next_lo++, lo, sizeof(*lo)); memcpy(comb_next_lo++, lo, sizeof(*lo));
} }

View File

@ -1365,7 +1365,7 @@ void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr,
int save_errno = errno; int save_errno = errno;
if (addr.s_addr == INADDR_ANY) if (addr.s_addr == INADDR_ANY)
strcpy(buf, "*"); strlcpy(buf, "*", buf_size);
else { else {
if (!inet_ntop(AF_INET, &addr, buf, buf_size)) { if (!inet_ntop(AF_INET, &addr, buf, buf_size)) {
if (onfail) if (onfail)

View File

@ -1659,7 +1659,7 @@ static struct vty *vty_create(int vty_sock, union sockunion *su)
/* configurable parameters not part of basic init */ /* configurable parameters not part of basic init */
vty->v_timeout = vty_timeout_val; vty->v_timeout = vty_timeout_val;
strcpy(vty->address, buf); strlcpy(vty->address, buf, sizeof(vty->address));
if (no_password_check) { if (no_password_check) {
if (host.advanced) if (host.advanced)
vty->node = ENABLE_NODE; vty->node = ENABLE_NODE;
@ -1795,7 +1795,7 @@ struct vty *vty_stdio(void (*atclose)(int isexit))
*/ */
vty->node = ENABLE_NODE; vty->node = ENABLE_NODE;
vty->v_timeout = 0; vty->v_timeout = 0;
strcpy(vty->address, "console"); strlcpy(vty->address, "console", sizeof(vty->address));
vty_stdio_resume(); vty_stdio_resume();
return vty; return vty;
@ -2384,9 +2384,10 @@ static FILE *vty_use_backup_config(const char *fullpath)
int c; int c;
char buffer[512]; char buffer[512];
fullpath_sav = malloc(strlen(fullpath) + strlen(CONF_BACKUP_EXT) + 1); size_t fullpath_sav_sz = strlen(fullpath) + strlen(CONF_BACKUP_EXT) + 1;
strcpy(fullpath_sav, fullpath); fullpath_sav = malloc(fullpath_sav_sz);
strcat(fullpath_sav, CONF_BACKUP_EXT); strlcpy(fullpath_sav, fullpath, fullpath_sav_sz);
strlcat(fullpath_sav, CONF_BACKUP_EXT, fullpath_sav_sz);
sav = open(fullpath_sav, O_RDONLY); sav = open(fullpath_sav, O_RDONLY);
if (sav < 0) { if (sav < 0) {
@ -3079,8 +3080,9 @@ static void vty_save_cwd(void)
} }
} }
vty_cwd = XMALLOC(MTYPE_TMP, strlen(cwd) + 1); size_t vty_cwd_sz = strlen(cwd) + 1;
strcpy(vty_cwd, cwd); vty_cwd = XMALLOC(MTYPE_TMP, vty_cwd_sz);
strlcpy(vty_cwd, cwd, vty_cwd_sz);
} }
char *vty_get_cwd(void) char *vty_get_cwd(void)