diff options
author | Phil Sutter <phil@nwl.cc> | 2022-03-24 18:27:56 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2022-03-28 12:19:44 +0200 |
commit | ff4e57e890a8628208a004587cd7a5ee955bb5fe (patch) | |
tree | 99ef718ee4ac73a3c307a81de0e362fd5af07e69 /src | |
parent | 0e05989f3247e9aef0d96aafc144b2d853732891 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/helpers/ftp.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/helpers/ftp.c b/src/helpers/ftp.c index 29ac55c..2b34534 100644 --- a/src/helpers/ftp.c +++ b/src/helpers/ftp.c @@ -332,23 +332,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); } |