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

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