Blame SOURCES/0012-helpers-ftp-Avoid-ugly-casts.patch

4a3166
From 2c8cc74e2fbfbed8fad8e80513fc7a34674bb382 Mon Sep 17 00:00:00 2001
4a3166
From: Phil Sutter <phil@nwl.cc>
4a3166
Date: Thu, 24 Mar 2022 18:27:56 +0100
4a3166
Subject: [PATCH] helpers: ftp: Avoid ugly casts
4a3166
4a3166
Coverity tool complains about accessing a local variable at non-zero
4a3166
offset. Avoid this by using a helper union. This should silence the
4a3166
checker, although the code is still probably not Big Endian-safe.
4a3166
4a3166
Signed-off-by: Phil Sutter <phil@nwl.cc>
4a3166
(cherry picked from commit ff4e57e890a8628208a004587cd7a5ee955bb5fe)
4a3166
---
4a3166
 src/helpers/ftp.c | 20 +++++++++-----------
4a3166
 1 file changed, 9 insertions(+), 11 deletions(-)
4a3166
4a3166
diff --git a/src/helpers/ftp.c b/src/helpers/ftp.c
4a3166
index bd3f11788cc24..0694d38c6ea13 100644
4a3166
--- a/src/helpers/ftp.c
4a3166
+++ b/src/helpers/ftp.c
4a3166
@@ -331,23 +331,21 @@ static int nf_nat_ftp_fmt_cmd(enum nf_ct_ftp_type type,
4a3166
 			      char *buffer, size_t buflen,
4a3166
 			      uint32_t addr, uint16_t port)
4a3166
 {
4a3166
+	union {
4a3166
+		unsigned char c[4];
4a3166
+		uint32_t d;
4a3166
+	} tmp;
4a3166
+
4a3166
+	tmp.d = addr;
4a3166
 	switch (type) {
4a3166
 	case NF_CT_FTP_PORT:
4a3166
 	case NF_CT_FTP_PASV:
4a3166
 		return snprintf(buffer, buflen, "%u,%u,%u,%u,%u,%u",
4a3166
-				((unsigned char *)&addr)[0],
4a3166
-				((unsigned char *)&addr)[1],
4a3166
-				((unsigned char *)&addr)[2],
4a3166
-				((unsigned char *)&addr)[3],
4a3166
-				port >> 8,
4a3166
-				port & 0xFF);
4a3166
+				tmp.c[0], tmp.c[1], tmp.c[2], tmp.c[3],
4a3166
+				port >> 8, port & 0xFF);
4a3166
 	case NF_CT_FTP_EPRT:
4a3166
 		return snprintf(buffer, buflen, "|1|%u.%u.%u.%u|%u|",
4a3166
-				((unsigned char *)&addr)[0],
4a3166
-				((unsigned char *)&addr)[1],
4a3166
-				((unsigned char *)&addr)[2],
4a3166
-				((unsigned char *)&addr)[3],
4a3166
-				port);
4a3166
+				tmp.c[0], tmp.c[1], tmp.c[2], tmp.c[3], port);
4a3166
 	case NF_CT_FTP_EPSV:
4a3166
 		return snprintf(buffer, buflen, "|||%u|", port);
4a3166
 	}
4a3166
-- 
4a3166
2.34.1
4a3166