From b5bc748a38cf88e8fa52fb8f55bf8014a188a9b9 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Tue, 11 Feb 2025 15:38:21 +0000 Subject: T7156: suppress sprintf format warnings at the source level (#13) rather than with CFLAGS, so that it applies only to locations where it was proven safe and is protected against CFLAGS overrides --- src/Makefile.am | 2 +- src/ipaddrcheck_functions.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 1c43bae..6098ae5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -AM_CFLAGS = --pedantic -Wall -Werror -Wno-error=format-overflow= -std=c99 -O2 +AM_CFLAGS = --pedantic -Wall -Werror -std=c99 -O2 AM_LDFLAGS = ipaddrcheck_SOURCES = ipaddrcheck.c ipaddrcheck_functions.c diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c index 034fd54..d486d07 100644 --- a/src/ipaddrcheck_functions.c +++ b/src/ipaddrcheck_functions.c @@ -578,10 +578,13 @@ int is_ipv4_range(char* range_str, int prefix_length, int verbose) { char left_pref_str[19]; - /* XXX: Prefix length size is checked elsewhere, so it can't be more than 2 characters (32) + /* XXX: Prefix length size is checked elsewhere with a regex, so it can't be more than 2 characters (32) and overflow cannot occur. */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-overflow=" sprintf(left_pref_str, "%s/%u", left, prefix_length); + #pragma GCC diagnostic pop CIDR* left_addr_with_pref = cidr_from_str(left_pref_str); CIDR* left_net = cidr_addr_network(left_addr_with_pref); if( cidr_contains(left_net, right_addr) == 0 ) @@ -679,10 +682,13 @@ int is_ipv6_range(char* range_str, int prefix_length, int verbose) { char left_pref_str[44]; - /* XXX: Prefix length size is checked elsewhere, so it can't be more than 3 characters (128) + /* XXX: Prefix length size is checked elsewhere with a regex, so it can't be more than 3 characters (128) and overflow cannot occur. */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-overflow=" sprintf(left_pref_str, "%s/%u", left, prefix_length); + #pragma GCC diagnostic pop CIDR* left_addr_with_pref = cidr_from_str(left_pref_str); CIDR* left_net = cidr_addr_network(left_addr_with_pref); if( cidr_contains(left_net, right_addr) == 0 ) -- cgit v1.2.3