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