From 08808541857dc78edd5bfd70f776bfbe58b44051 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 21 Apr 2020 12:56:42 -0400 Subject: [PATCH] pimd, lib: suppress compiler warnings on snprintf truncation warnings on old compilers Signed-off-by: Quentin Young --- lib/log_vty.c | 10 +++++++++- pimd/pim_cmd.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/log_vty.c b/lib/log_vty.c index d46fef15ae..d1dcac2340 100644 --- a/lib/log_vty.c +++ b/lib/log_vty.c @@ -277,7 +277,15 @@ static int set_log_file(struct zlog_cfg_file *target, struct vty *vty, return CMD_WARNING_CONFIG_FAILED; } - snprintf(path, sizeof(path), "%s/%s", cwd, fname); + int pr = snprintf(path, sizeof(path), "%s/%s", cwd, fname); + if (pr < 0 || (unsigned int)pr >= sizeof(path)) { + flog_err_sys( + EC_LIB_SYSTEM_CALL, + "%s: Path too long ('%s/%s'); system maximum is %u", + __func__, cwd, fname, MAXPATHLEN); + return CMD_WARNING_CONFIG_FAILED; + } + fullpath = path; } else fullpath = fname; diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index cdda7c03aa..7f75660011 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -2510,8 +2510,8 @@ static void pim_show_upstream(struct pim_instance *pim, struct vty *vty, pim_upstream_state2brief_str(up->join_state, state_str, sizeof(state_str)); if (up->reg_state != PIM_REG_NOINFO) { char tmp_str[PIM_REG_STATE_STR_LEN]; + char tmp[sizeof(state_str) + 1]; - char tmp[sizeof(state_str)]; snprintf(tmp, sizeof(tmp), ",%s", pim_reg_state2brief_str(up->reg_state, tmp_str, sizeof(tmp_str))); -- 2.39.5