summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2023-01-26 14:53:47 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2023-01-27 12:01:20 +0100
commitc84e51870940311bb6ec67d8b192da1ce32cba8f (patch)
tree5d1c214da53ca54b575e0b9e7c66d3c2422b1751
parent0f9de11a11644b77cc60d6ff6ac4519d2e5c29e1 (diff)
*: no-warn pragmas for non-const format strings
We do use non-constant/literal format strings in a few places for more or less valid reasons; put `ignored "-Wformat-nonliteral"` around those so we can have the warning enabled for everywhere else. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--bgpd/bgp_dump.c4
-rw-r--r--ldpd/log.c4
-rw-r--r--lib/printf/glue.c4
-rw-r--r--lib/printf/vfprintf.c6
-rw-r--r--lib/vty.c14
-rw-r--r--lib/yang_translator.c8
-rw-r--r--lib/zlog.c8
-rw-r--r--vtysh/vtysh.c14
-rw-r--r--watchfrr/watchfrr.c4
9 files changed, 66 insertions, 0 deletions
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c
index 254996edad..98a2f95ead 100644
--- a/bgpd/bgp_dump.c
+++ b/bgpd/bgp_dump.c
@@ -117,9 +117,13 @@ static FILE *bgp_dump_open_file(struct bgp_dump *bgp_dump)
if (bgp_dump->filename[0] != DIRECTORY_SEP) {
snprintf(fullpath, sizeof(fullpath), "%s/%s", vty_get_cwd(),
bgp_dump->filename);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* user supplied date/time format string */
ret = strftime(realpath, MAXPATHLEN, fullpath, &tm);
} else
ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, &tm);
+#pragma GCC diagnostic pop
if (ret == 0) {
flog_warn(EC_BGP_DUMP, "%s: strftime error", __func__);
diff --git a/ldpd/log.c b/ldpd/log.c
index 1aaad41a10..88ce03095a 100644
--- a/ldpd/log.c
+++ b/ldpd/log.c
@@ -77,7 +77,11 @@ log_warn(const char *emsg, ...)
vlog(LOG_ERR, emsg, ap);
logit(LOG_ERR, "%s", strerror(errno));
} else {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* format extended above */
vlog(LOG_ERR, nfmt, ap);
+#pragma GCC diagnostic pop
free(nfmt);
}
va_end(ap);
diff --git a/lib/printf/glue.c b/lib/printf/glue.c
index 6e39c2d9cf..3ac6e2c0ae 100644
--- a/lib/printf/glue.c
+++ b/lib/printf/glue.c
@@ -293,5 +293,9 @@ static ssize_t printfrr_va(struct fbuf *buf, struct printfrr_eargs *ea,
* when allocating a larger buffer in asnprintfrr()
*/
va_copy(ap, *vaf->va);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* can't format check this */
return vbprintfrr(buf, vaf->fmt, ap);
+#pragma GCC diagnostic pop
}
diff --git a/lib/printf/vfprintf.c b/lib/printf/vfprintf.c
index 49fa2b718f..cc886834fa 100644
--- a/lib/printf/vfprintf.c
+++ b/lib/printf/vfprintf.c
@@ -504,14 +504,20 @@ reswitch: switch (ch) {
fmt[4] = ch;
fmt[5] = '\0';
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
snprintf(buf, sizeof(buf), fmt, prec, arg);
+#pragma GCC diagnostic pop
} else {
double arg = GETARG(double);
char fmt[5] = "%.*";
fmt[3] = ch;
fmt[4] = '\0';
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
snprintf(buf, sizeof(buf), fmt, prec, arg);
+#pragma GCC diagnostic pop
}
cp = buf;
/* for proper padding */
diff --git a/lib/vty.c b/lib/vty.c
index 352080e580..76d907408c 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -343,6 +343,15 @@ void vty_hello(struct vty *vty)
vty_out(vty, "%s", host.motd);
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+/* prompt formatting has a %s in the cmd_node prompt string.
+ *
+ * Also for some reason GCC emits the warning on the end of the function
+ * (optimization maybe?) rather than on the vty_out line, so this pragma
+ * wraps the entire function rather than just the vty_out line.
+ */
+
/* Put out prompt and wait input from user. */
static void vty_prompt(struct vty *vty)
{
@@ -350,6 +359,7 @@ static void vty_prompt(struct vty *vty)
vty_out(vty, cmd_prompt(vty->node), cmd_hostname_get());
}
}
+#pragma GCC diagnostic pop
/* Send WILL TELOPT_ECHO to remote server. */
static void vty_will_echo(struct vty *vty)
@@ -464,8 +474,12 @@ static int vty_command(struct vty *vty, char *buf)
vty->address);
/* format the prompt */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* prompt formatting has a %s in the cmd_node prompt string */
snprintf(prompt_str, sizeof(prompt_str), cmd_prompt(vty->node),
vty_str);
+#pragma GCC diagnostic pop
/* now log the command */
zlog_notice("%s%s", prompt_str, buf);
diff --git a/lib/yang_translator.c b/lib/yang_translator.c
index d562e4d29e..67b7f9aa70 100644
--- a/lib/yang_translator.c
+++ b/lib/yang_translator.c
@@ -339,8 +339,12 @@ yang_translate_xpath(const struct yang_translator *translator, int dir,
if (!mapping)
return YANG_TRANSLATE_NOTFOUND;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* processing format strings from mapping node... */
n = sscanf(xpath, mapping->xpath_from_fmt, keys[0], keys[1], keys[2],
keys[3]);
+#pragma GCC diagnostic pop
if (n < 0) {
flog_warn(EC_LIB_YANG_TRANSLATION_ERROR,
"%s: sscanf() failed: %s", __func__,
@@ -348,8 +352,12 @@ yang_translate_xpath(const struct yang_translator *translator, int dir,
return YANG_TRANSLATE_FAILURE;
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* processing format strings from mapping node... */
snprintf(xpath, xpath_len, mapping->xpath_to_fmt, keys[0], keys[1],
keys[2], keys[3]);
+#pragma GCC diagnostic pop
return YANG_TRANSLATE_SUCCESS;
}
diff --git a/lib/zlog.c b/lib/zlog.c
index 6a36a0b123..e08d22b2b9 100644
--- a/lib/zlog.c
+++ b/lib/zlog.c
@@ -743,7 +743,11 @@ const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
fb.outpos_i = 0;
va_copy(args, msg->args);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* format-string checking is done further up the chain */
need += vbprintfrr(&fb, msg->fmt, args);
+#pragma GCC diagnostic pop
va_end(args);
msg->textlen = need;
@@ -762,7 +766,11 @@ const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
fb.outpos_i = 0;
va_copy(args, msg->args);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* same as above */
vbprintfrr(&fb, msg->fmt, args);
+#pragma GCC diagnostic pop
va_end(args);
bputch(&fb, '\n');
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index dea09fa151..7885188483 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -2759,6 +2759,15 @@ static char *do_prepend(struct vty *vty, struct cmd_token **argv, int argc)
return frrstr_join(argstr, argc + off, " ");
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+/* 'headline' is a format string with a %s for the daemon name
+ *
+ * Also for some reason GCC emits the warning on the end of the function
+ * (optimization maybe?) rather than on the vty_out line, so this pragma
+ * wraps the entire function rather than just the vty_out line.
+ */
+
static int show_per_daemon(struct vty *vty, struct cmd_token **argv, int argc,
const char *headline)
{
@@ -2777,6 +2786,7 @@ static int show_per_daemon(struct vty *vty, struct cmd_token **argv, int argc,
return ret;
}
+#pragma GCC diagnostic pop
static int show_one_daemon(struct vty *vty, struct cmd_token **argv, int argc,
const char *name)
@@ -4353,7 +4363,11 @@ char *vtysh_prompt(void)
{
static char buf[512];
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* prompt formatting has a %s in the cmd_node prompt string. */
snprintf(buf, sizeof(buf), cmd_prompt(vty->node), cmd_hostname_get());
+#pragma GCC diagnostic pop
return buf;
}
diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c
index 4a3575ae75..f1cc84bc78 100644
--- a/watchfrr/watchfrr.c
+++ b/watchfrr/watchfrr.c
@@ -512,7 +512,11 @@ static int run_job(struct restart_info *restart, const char *cmdtype,
restart->kills = 0;
{
char cmd[strlen(command) + strlen(restart->name) + 1];
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ /* user supplied command string has a %s for the daemon name */
snprintf(cmd, sizeof(cmd), command, restart->name);
+#pragma GCC diagnostic pop
if ((restart->pid = run_background(cmd)) > 0) {
thread_add_timer(master, restart_kill, restart,
gs.restart_timeout, &restart->t_kill);