Netfilter-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] libiptc.c: pragma disable a gcc compiler warning
@ 2020-05-11 21:34 Maciej Żenczykowski
  2020-05-14 17:58 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Maciej Żenczykowski @ 2020-05-11 21:34 UTC (permalink / raw)
  To: Maciej Żenczykowski, Pablo Neira Ayuso, Florian Westphal
  Cc: Linux Network Development Mailing List,
	Netfilter Development Mailing List

From: Maciej Żenczykowski <maze@google.com>

Fixes:
  In file included from libip4tc.c:113:
  In function ‘iptcc_compile_chain’,
      inlined from ‘iptcc_compile_table’ at libiptc.c:1246:13,
      inlined from ‘iptc_commit’ at libiptc.c:2575:8,
      inlined from ‘iptc_commit’ at libiptc.c:2513:1:
  libiptc.c:1172:2: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
   1172 |  memcpy(&foot->e.counters, &c->counters, sizeof(STRUCT_COUNTERS));
        |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from ../include/libiptc/libiptc.h:12,
                   from libip4tc.c:29:
  libiptc.c: In function ‘iptc_commit’:
  ../include/linux/netfilter_ipv4/ip_tables.h:202:19: note: at offset 0 to object ‘entries’ with size 0 declared here
    202 |  struct ipt_entry entries[0];
        |                   ^~~~~~~

Which was found via compilation on Fedora 32.

Test: builds without warnings
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
 libiptc/libiptc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
index 58882015..1a92b267 100644
--- a/libiptc/libiptc.c
+++ b/libiptc/libiptc.c
@@ -1169,7 +1169,10 @@ static int iptcc_compile_chain(struct xtc_handle *h, STRUCT_REPLACE *repl, struc
 	else
 		foot->target.verdict = RETURN;
 	/* set policy-counters */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
 	memcpy(&foot->e.counters, &c->counters, sizeof(STRUCT_COUNTERS));
+#pragma GCC diagnostic pop
 
 	return 0;
 }
-- 
2.26.2.645.ge9eca65c58-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libiptc.c: pragma disable a gcc compiler warning
  2020-05-11 21:34 [PATCH] libiptc.c: pragma disable a gcc compiler warning Maciej Żenczykowski
@ 2020-05-14 17:58 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2020-05-14 17:58 UTC (permalink / raw)
  To: Maciej Żenczykowski
  Cc: Maciej Żenczykowski, Florian Westphal,
	Linux Network Development Mailing List,
	Netfilter Development Mailing List

On Mon, May 11, 2020 at 02:34:04PM -0700, Maciej Żenczykowski wrote:
> From: Maciej Żenczykowski <maze@google.com>
> 
> Fixes:
>   In file included from libip4tc.c:113:
>   In function ‘iptcc_compile_chain’,
>       inlined from ‘iptcc_compile_table’ at libiptc.c:1246:13,
>       inlined from ‘iptc_commit’ at libiptc.c:2575:8,
>       inlined from ‘iptc_commit’ at libiptc.c:2513:1:
>   libiptc.c:1172:2: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
>    1172 |  memcpy(&foot->e.counters, &c->counters, sizeof(STRUCT_COUNTERS));
>         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   In file included from ../include/libiptc/libiptc.h:12,
>                    from libip4tc.c:29:
>   libiptc.c: In function ‘iptc_commit’:
>   ../include/linux/netfilter_ipv4/ip_tables.h:202:19: note: at offset 0 to object ‘entries’ with size 0 declared here
>     202 |  struct ipt_entry entries[0];
>         |                   ^~~~~~~
> 
> Which was found via compilation on Fedora 32.
> 
> Test: builds without warnings
> Signed-off-by: Maciej Żenczykowski <maze@google.com>
> ---
>  libiptc/libiptc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
> index 58882015..1a92b267 100644
> --- a/libiptc/libiptc.c
> +++ b/libiptc/libiptc.c
> @@ -1169,7 +1169,10 @@ static int iptcc_compile_chain(struct xtc_handle *h, STRUCT_REPLACE *repl, struc
>  	else
>  		foot->target.verdict = RETURN;
>  	/* set policy-counters */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wstringop-overflow"
>  	memcpy(&foot->e.counters, &c->counters, sizeof(STRUCT_COUNTERS));
> +#pragma GCC diagnostic pop

Probably make a casting from foot->e.counters to the counters object
to make gcc happy?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 21:34 [PATCH] libiptc.c: pragma disable a gcc compiler warning Maciej Żenczykowski
2020-05-14 17:58 ` Pablo Neira Ayuso

Netfilter-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netfilter-devel/0 netfilter-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netfilter-devel netfilter-devel/ https://lore.kernel.org/netfilter-devel \
		netfilter-devel@vger.kernel.org
	public-inbox-index netfilter-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netfilter-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git