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

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