Skip to content

Commit

Permalink
ui/curses: always use "%s"-style format for printf()-style functions
Browse files Browse the repository at this point in the history
`ncuses-6.3` added printf-style function attributes and now makes
it easier to catch cases when user input is used in palce of format
string when built with CFLAGS=-Werror=format-security:

  ui/curses.c:765:42:
    error: format not a string literal and no format arguments [-Werror=format-security]
    765 |         mvprintw(rowstat - 1, startstat, msg);
        |                                          ^~~

Let's wrap all the missing places with "%s" format.
  • Loading branch information
trofi committed Nov 1, 2021
1 parent ec42ba6 commit aeb493e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ui/curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static void mtr_curses_hosts(
attron(A_BOLD);
#ifdef HAVE_IPINFO
if (is_printii(ctl))
printw(fmt_ipinfo(ctl, addr));
printw("%s", fmt_ipinfo(ctl, addr));
#endif
if (name != NULL) {
if (ctl->show_ips)
Expand Down Expand Up @@ -485,7 +485,7 @@ static void mtr_curses_hosts(
printw("\n ");
#ifdef HAVE_IPINFO
if (is_printii(ctl))
printw(fmt_ipinfo(ctl, addrs));
printw("%s", fmt_ipinfo(ctl, addrs));
#endif
if (name != NULL) {
if (ctl->show_ips)
Expand Down Expand Up @@ -650,7 +650,7 @@ static void mtr_curses_graph(

#ifdef HAVE_IPINFO
if (is_printii(ctl))
printw(fmt_ipinfo(ctl, addr));
printw("%s", fmt_ipinfo(ctl, addr));
#endif
name = dns_lookup(ctl, addr);
printw("%s", name ? name : strlongip(ctl->af, addr));
Expand Down Expand Up @@ -702,7 +702,7 @@ void mtr_curses_redraw(
ctl->LocalHostname, net_localaddr(),
ctl->Hostname, net_remoteaddr());
t = time(NULL);
mvprintw(1, maxx - 25, iso_time(&t));
mvprintw(1, maxx - 25, "%s", iso_time(&t));
printw("\n");

printw("Keys: ");
Expand Down Expand Up @@ -762,7 +762,7 @@ void mtr_curses_redraw(
startstat = padding - 2;

snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);
mvprintw(rowstat - 1, startstat, msg);
mvprintw(rowstat - 1, startstat, "%s", msg);

attroff(A_BOLD);
move(rowstat, 0);
Expand Down

0 comments on commit aeb493e

Please sign in to comment.