All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [conntrack-tools PATCH 4/8] helpers: ftp: Avoid ugly casts
Date: Fri, 25 Mar 2022 11:49:59 +0100	[thread overview]
Message-ID: <20220325105003.26621-5-phil@nwl.cc> (raw)
In-Reply-To: <20220325105003.26621-1-phil@nwl.cc>

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>
---
 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 29ac55c236507..2b345340a70b9 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);
 	}
-- 
2.34.1


  parent reply	other threads:[~2022-03-25 10:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 10:49 [conntrack-tools PATCH 0/8] Fixes for a recent Coverity tool run Phil Sutter
2022-03-25 10:49 ` [conntrack-tools PATCH 1/8] hash: Flush tables when destroying Phil Sutter
2022-03-25 10:49 ` [conntrack-tools PATCH 2/8] cache: Fix features array allocation Phil Sutter
2022-03-25 10:49 ` [conntrack-tools PATCH 3/8] Fix potential buffer overrun in snprintf() calls Phil Sutter
2022-03-25 10:49 ` Phil Sutter [this message]
2022-03-25 10:50 ` [conntrack-tools PATCH 5/8] read_config_yy: Drop extra argument from dlog() call Phil Sutter
2022-03-25 10:50 ` [conntrack-tools PATCH 6/8] Don't call exit() from signal handler Phil Sutter
2022-03-25 10:50 ` [conntrack-tools PATCH 7/8] Drop pointless assignments Phil Sutter
2022-03-25 10:50 ` [conntrack-tools PATCH 8/8] connntrack: Fix for memleak when parsing -j arg Phil Sutter
2022-03-28  8:25 ` [conntrack-tools PATCH 0/8] Fixes for a recent Coverity tool run Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220325105003.26621-5-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.