Blame SOURCES/0003-Eliminate-inet_aton-and-inet_ntoa.patch

3a00e5
From 76a32fe33a948ddce6b9cacee5400d83b0a6cdba Mon Sep 17 00:00:00 2001
3a00e5
From: Phil Sutter <phil@nwl.cc>
3a00e5
Date: Tue, 27 Apr 2021 09:12:53 +0200
3a00e5
Subject: [PATCH] Eliminate inet_aton() and inet_ntoa()
3a00e5
3a00e5
Both functions are obsolete, replace them by equivalent calls to
3a00e5
inet_pton() and inet_ntop().
3a00e5
3a00e5
Signed-off-by: Phil Sutter <phil@nwl.cc>
3a00e5
(cherry picked from commit acac2dbe64e5120394fa715bb5fe95c42d08b8b3)
3a00e5
---
3a00e5
 extensions/libebt_among.c |  6 ++++--
3a00e5
 iptables/nft-ipv4.c       | 23 ++++++++++++++---------
3a00e5
 2 files changed, 18 insertions(+), 11 deletions(-)
3a00e5
3a00e5
diff --git a/extensions/libebt_among.c b/extensions/libebt_among.c
3a00e5
index 2b9a1b6566684..7eb898f984bba 100644
3a00e5
--- a/extensions/libebt_among.c
3a00e5
+++ b/extensions/libebt_among.c
3a00e5
@@ -66,7 +66,7 @@ parse_nft_among_pair(char *buf, struct nft_among_pair *pair, bool have_ip)
3a00e5
 	if (sep) {
3a00e5
 		*sep = '\0';
3a00e5
 
3a00e5
-		if (!inet_aton(sep + 1, &pair->in))
3a00e5
+		if (!inet_pton(AF_INET, sep + 1, &pair->in))
3a00e5
 			xtables_error(PARAMETER_PROBLEM,
3a00e5
 				      "Invalid IP address '%s'\n", sep + 1);
3a00e5
 	}
3a00e5
@@ -194,6 +194,7 @@ static void __bramong_print(struct nft_among_pair *pairs,
3a00e5
 			    int cnt, bool inv, bool have_ip)
3a00e5
 {
3a00e5
 	const char *isep = inv ? "! " : "";
3a00e5
+	char abuf[INET_ADDRSTRLEN];
3a00e5
 	int i;
3a00e5
 
3a00e5
 	for (i = 0; i < cnt; i++) {
3a00e5
@@ -202,7 +203,8 @@ static void __bramong_print(struct nft_among_pair *pairs,
3a00e5
 
3a00e5
 		printf("%s", ether_ntoa(&pairs[i].ether));
3a00e5
 		if (pairs[i].in.s_addr != INADDR_ANY)
3a00e5
-			printf("=%s", inet_ntoa(pairs[i].in));
3a00e5
+			printf("=%s", inet_ntop(AF_INET, &pairs[i].in,
3a00e5
+						abuf, sizeof(abuf)));
3a00e5
 	}
3a00e5
 	printf(" ");
3a00e5
 }
3a00e5
diff --git a/iptables/nft-ipv4.c b/iptables/nft-ipv4.c
3a00e5
index 0d32a30010519..a5b835b1f681d 100644
3a00e5
--- a/iptables/nft-ipv4.c
3a00e5
+++ b/iptables/nft-ipv4.c
3a00e5
@@ -136,7 +136,7 @@ static void get_frag(struct nft_xt_ctx *ctx, struct nftnl_expr *e, bool *inv)
3a00e5
 
3a00e5
 static const char *mask_to_str(uint32_t mask)
3a00e5
 {
3a00e5
-	static char mask_str[sizeof("255.255.255.255")];
3a00e5
+	static char mask_str[INET_ADDRSTRLEN];
3a00e5
 	uint32_t bits, hmask = ntohl(mask);
3a00e5
 	struct in_addr mask_addr = {
3a00e5
 		.s_addr = mask,
3a00e5
@@ -155,7 +155,7 @@ static const char *mask_to_str(uint32_t mask)
3a00e5
 	if (i >= 0)
3a00e5
 		sprintf(mask_str, "%u", i);
3a00e5
 	else
3a00e5
-		sprintf(mask_str, "%s", inet_ntoa(mask_addr));
3a00e5
+		inet_ntop(AF_INET, &mask_addr, mask_str, sizeof(mask_str));
3a00e5
 
3a00e5
 	return mask_str;
3a00e5
 }
3a00e5
@@ -298,10 +298,13 @@ static void nft_ipv4_print_rule(struct nft_handle *h, struct nftnl_rule *r,
3a00e5
 static void save_ipv4_addr(char letter, const struct in_addr *addr,
3a00e5
 			   uint32_t mask, int invert)
3a00e5
 {
3a00e5
+	char addrbuf[INET_ADDRSTRLEN];
3a00e5
+
3a00e5
 	if (!mask && !invert && !addr->s_addr)
3a00e5
 		return;
3a00e5
 
3a00e5
-	printf("%s-%c %s/%s ", invert ? "! " : "", letter, inet_ntoa(*addr),
3a00e5
+	printf("%s-%c %s/%s ", invert ? "! " : "", letter,
3a00e5
+	       inet_ntop(AF_INET, addr, addrbuf, sizeof(addrbuf)),
3a00e5
 	       mask_to_str(mask));
3a00e5
 }
3a00e5
 
3a00e5
@@ -387,25 +390,27 @@ static void xlate_ipv4_addr(const char *selector, const struct in_addr *addr,
3a00e5
 			    const struct in_addr *mask,
3a00e5
 			    bool inv, struct xt_xlate *xl)
3a00e5
 {
3a00e5
+	char mbuf[INET_ADDRSTRLEN], abuf[INET_ADDRSTRLEN];
3a00e5
 	const char *op = inv ? "!= " : "";
3a00e5
 	int cidr;
3a00e5
 
3a00e5
 	if (!inv && !addr->s_addr && !mask->s_addr)
3a00e5
 		return;
3a00e5
 
3a00e5
+	inet_ntop(AF_INET, addr, abuf, sizeof(abuf));
3a00e5
+
3a00e5
 	cidr = xtables_ipmask_to_cidr(mask);
3a00e5
 	switch (cidr) {
3a00e5
 	case -1:
3a00e5
-		/* inet_ntoa() is not reentrant */
3a00e5
-		xt_xlate_add(xl, "%s & %s ", selector, inet_ntoa(*mask));
3a00e5
-		xt_xlate_add(xl, "%s %s ", inv ? "!=" : "==", inet_ntoa(*addr));
3a00e5
+		xt_xlate_add(xl, "%s & %s %s %s ", selector,
3a00e5
+			     inet_ntop(AF_INET, mask, mbuf, sizeof(mbuf)),
3a00e5
+			     inv ? "!=" : "==", abuf);
3a00e5
 		break;
3a00e5
 	case 32:
3a00e5
-		xt_xlate_add(xl, "%s %s%s ", selector, op, inet_ntoa(*addr));
3a00e5
+		xt_xlate_add(xl, "%s %s%s ", selector, op, abuf);
3a00e5
 		break;
3a00e5
 	default:
3a00e5
-		xt_xlate_add(xl, "%s %s%s/%d ", selector, op, inet_ntoa(*addr),
3a00e5
-			     cidr);
3a00e5
+		xt_xlate_add(xl, "%s %s%s/%d ", selector, op, abuf, cidr);
3a00e5
 	}
3a00e5
 }
3a00e5
 
3a00e5
-- 
3a00e5
2.31.1
3a00e5