From: Rosen Penev Date: Thu, 21 Jun 2018 23:09:56 +0000 (-0700) Subject: firewall3: Fix GCC8 warnings by replacing sprintf with snprintf X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=72684e5bb8d3a7deb0cfdafa77b40be0b6360ccd;p=oweals%2Ffirewall3.git firewall3: Fix GCC8 warnings by replacing sprintf with snprintf error: ‘%u’ directive writing between 1 and 10 bytes into a region of size between 7 and 11 [-Werror=format-overflow=] sprintf(buf, "%u-%u", port->port_min, port->port_max); ^~ note: directive argument in the range [0, 2147483647] sprintf(buf, "%u-%u", port->port_min, port->port_max); ^~~~~~~ note: ‘sprintf’ output between 4 and 17 bytes into a destination of size 13 sprintf(buf, "%u-%u", port->port_min, port->port_max); Signed-off-by: Rosen Penev --- diff --git a/iptables.c b/iptables.c index f8d4d46..adf64c0 100644 --- a/iptables.c +++ b/iptables.c @@ -899,7 +899,7 @@ fw3_ipt_rule_sport_dport(struct fw3_ipt_rule *r, if (sp->port_min == sp->port_max) sprintf(buf, "%u", sp->port_min); else - sprintf(buf, "%u:%u", sp->port_min, sp->port_max); + snprintf(buf, sizeof(buf), "%u:%u", sp->port_min, sp->port_max); fw3_ipt_rule_addarg(r, sp->invert, "--sport", buf); } @@ -909,7 +909,7 @@ fw3_ipt_rule_sport_dport(struct fw3_ipt_rule *r, if (dp->port_min == dp->port_max) sprintf(buf, "%u", dp->port_min); else - sprintf(buf, "%u:%u", dp->port_min, dp->port_max); + snprintf(buf, sizeof(buf), "%u:%u", dp->port_min, dp->port_max); fw3_ipt_rule_addarg(r, dp->invert, "--dport", buf); } @@ -955,7 +955,7 @@ fw3_ipt_rule_icmptype(struct fw3_ipt_rule *r, struct fw3_icmptype *icmp) if (icmp->code6_min == 0 && icmp->code6_max == 0xFF) sprintf(buf, "%u", icmp->type6); else - sprintf(buf, "%u/%u", icmp->type6, icmp->code6_min); + snprintf(buf, sizeof(buf), "%u/%u", icmp->type6, icmp->code6_min); fw3_ipt_rule_addarg(r, icmp->invert, "--icmpv6-type", buf); } @@ -965,7 +965,7 @@ fw3_ipt_rule_icmptype(struct fw3_ipt_rule *r, struct fw3_icmptype *icmp) if (icmp->code_min == 0 && icmp->code_max == 0xFF) sprintf(buf, "%u", icmp->type); else - sprintf(buf, "%u/%u", icmp->type, icmp->code_min); + snprintf(buf, sizeof(buf), "%u/%u", icmp->type, icmp->code_min); fw3_ipt_rule_addarg(r, icmp->invert, "--icmp-type", buf); } diff --git a/redirects.c b/redirects.c index 7f9948c..6cd09f1 100644 --- a/redirects.c +++ b/redirects.c @@ -466,7 +466,7 @@ set_redirect(struct fw3_ipt_rule *r, struct fw3_port *port) if (port->port_min == port->port_max) sprintf(buf, "%u", port->port_min); else - sprintf(buf, "%u-%u", port->port_min, port->port_max); + snprintf(buf, sizeof(buf), "%u-%u", port->port_min, port->port_max); fw3_ipt_rule_addarg(r, false, "--to-ports", buf); }