diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command.c | 8 | ||||
| -rw-r--r-- | lib/command_match.c | 4 | ||||
| -rw-r--r-- | lib/libfrr.c | 4 | ||||
| -rw-r--r-- | lib/log.c | 2 | ||||
| -rw-r--r-- | lib/prefix.c | 2 | ||||
| -rw-r--r-- | lib/table.h | 2 | ||||
| -rw-r--r-- | lib/vty.c | 25 |
7 files changed, 24 insertions, 23 deletions
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/command_match.c b/lib/command_match.c index 8b34d1e3eb..9456e1585a 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -723,7 +723,7 @@ static enum match_type match_ipv4(const char *str) if (str - sp > 3) return no_match; - strncpy(buf, sp, str - sp); + memcpy(buf, sp, str - sp); if (atoi(buf) > 255) return no_match; @@ -774,7 +774,7 @@ static enum match_type match_ipv4_prefix(const char *str) if (str - sp > 3) return no_match; - strncpy(buf, sp, str - sp); + memcpy(buf, sp, str - sp); if (atoi(buf) > 255) return no_match; diff --git a/lib/libfrr.c b/lib/libfrr.c index 5970e70a6b..cd5a164c53 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_helpstr)); for (lo = os->longopts; lo->name; lo++) memcpy(comb_next_lo++, lo, sizeof(*lo)); } @@ -602,6 +602,8 @@ void zlog_backtrace_sigsafe(int priority, void *program_counter) backtrace_symbols_fd(array, size, FD); \ } #elif defined(HAVE_PRINTSTACK) + size = 0; + #define DUMP(FD) \ { \ if (program_counter) \ 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/table.h b/lib/table.h index 14be7ab656..eefd992546 100644 --- a/lib/table.h +++ b/lib/table.h @@ -298,6 +298,8 @@ static inline struct route_node *route_table_iter_next(route_table_iter_t *iter) return NULL; default: + /* Suppress uninitialized variable warning */ + node = NULL; assert(0); } @@ -84,7 +84,7 @@ static char *vty_ipv6_accesslist_name = NULL; static vector Vvty_serv_thread; /* Current directory. */ -char *vty_cwd = NULL; +char vty_cwd[MAXPATHLEN]; /* Login password check. */ static int no_password_check = 0; @@ -998,7 +998,7 @@ static void vty_describe_fold(struct vty *vty, int cmd_width, if (pos == 0) break; - strncpy(buf, p, pos); + memcpy(buf, p, pos); buf[pos] = '\0'; vty_out(vty, " %-*s %s\n", cmd_width, cmd, buf); @@ -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) { @@ -3055,10 +3056,9 @@ void vty_reset(void) static void vty_save_cwd(void) { - char cwd[MAXPATHLEN]; char *c; - c = getcwd(cwd, MAXPATHLEN); + c = getcwd(vty_cwd, sizeof(vty_cwd)); if (!c) { /* @@ -3072,15 +3072,12 @@ static void vty_save_cwd(void) SYSCONFDIR, errno); exit(-1); } - if (getcwd(cwd, MAXPATHLEN) == NULL) { + if (getcwd(vty_cwd, sizeof(vty_cwd)) == NULL) { flog_err_sys(EC_LIB_SYSTEM_CALL, "Failure to getcwd, errno: %d", errno); exit(-1); } } - - vty_cwd = XMALLOC(MTYPE_TMP, strlen(cwd) + 1); - strcpy(vty_cwd, cwd); } char *vty_get_cwd(void) @@ -3146,7 +3143,7 @@ void vty_init(struct thread_master *master_thread) void vty_terminate(void) { - XFREE(MTYPE_TMP, vty_cwd); + memset(vty_cwd, 0x00, sizeof(vty_cwd)); if (vtyvec && Vvty_serv_thread) { vty_reset(); |
