netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iptables] nfnl_osf: fix snprintf -Wformat-truncation warning
@ 2019-07-21 19:24 Fernando Fernandez Mancera
  2019-07-23 19:26 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Fernando Fernandez Mancera @ 2019-07-21 19:24 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Fernando Fernandez Mancera

Fedora 30 uses very recent gcc (version 9.1.1 20190503 (Red Hat 9.1.1-1)),
osf produces following warnings:

-Wformat-truncation warning have been introduced in the version 7.1 of gcc.
Also, remove a unneeded address check of "tmp + 1" in nf_osf_strchr().

nfnl_osf.c: In function ‘nfnl_osf_load_fingerprints’:
nfnl_osf.c:292:39: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 128 [-Wformat-truncation=]
  292 |   cnt = snprintf(obuf, sizeof(obuf), "%s,", pbeg);
      |                                       ^~
nfnl_osf.c:292:9: note: ‘snprintf’ output between 2 and 1025 bytes into a
destination of size 128
  292 |   cnt = snprintf(obuf, sizeof(obuf), "%s,", pbeg);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nfnl_osf.c:302:46: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 32 [-Wformat-truncation=]
  302 |    cnt = snprintf(f.genre, sizeof(f.genre), "%s", pbeg);
      |                                              ^~
nfnl_osf.c:302:10: note: ‘snprintf’ output between 1 and 1024 bytes into a
destination of size 32
  302 |    cnt = snprintf(f.genre, sizeof(f.genre), "%s", pbeg);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nfnl_osf.c:309:49: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 32 [-Wformat-truncation=]
  309 |   cnt = snprintf(f.version, sizeof(f.version), "%s", pbeg);
      |                                                 ^~
nfnl_osf.c:309:9: note: ‘snprintf’ output between 1 and 1024 bytes into a
destination of size 32
  309 |   cnt = snprintf(f.version, sizeof(f.version), "%s", pbeg);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nfnl_osf.c:317:47: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 32 [-Wformat-truncation=]
  317 |       snprintf(f.subtype, sizeof(f.subtype), "%s", pbeg);
      |                                               ^~
nfnl_osf.c:317:7: note: ‘snprintf’ output between 1 and 1024 bytes into a
destination of size 32
  317 |       snprintf(f.subtype, sizeof(f.subtype), "%s", pbeg);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
---
 utils/nfnl_osf.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/utils/nfnl_osf.c b/utils/nfnl_osf.c
index 0ea33fce..4ea9d2b3 100644
--- a/utils/nfnl_osf.c
+++ b/utils/nfnl_osf.c
@@ -343,31 +343,34 @@ static int osf_load_line(char *buffer, int len, int del)
 	pend = xt_osf_strchr(pbeg, OSFPDEL);
 	if (pend) {
 		*pend = '\0';
-		snprintf(obuf, sizeof(obuf), "%s,", pbeg);
+		i = sizeof(obuf);
+		snprintf(obuf, i, "%.*s,", i - 2, pbeg);
 		pbeg = pend + 1;
 	}
 
 	pend = xt_osf_strchr(pbeg, OSFPDEL);
 	if (pend) {
 		*pend = '\0';
+		i = sizeof(f.genre);
 		if (pbeg[0] == '@' || pbeg[0] == '*')
-			snprintf(f.genre, sizeof(f.genre), "%s", pbeg + 1);
-		else
-			snprintf(f.genre, sizeof(f.genre), "%s", pbeg);
+			pbeg++;
+		snprintf(f.genre, i, "%.*s", i - 1, pbeg);
 		pbeg = pend + 1;
 	}
 
 	pend = xt_osf_strchr(pbeg, OSFPDEL);
 	if (pend) {
 		*pend = '\0';
-		snprintf(f.version, sizeof(f.version), "%s", pbeg);
+		i = sizeof(f.version);
+		snprintf(f.version, i, "%.*s", i - 1, pbeg);
 		pbeg = pend + 1;
 	}
 
 	pend = xt_osf_strchr(pbeg, OSFPDEL);
 	if (pend) {
 		*pend = '\0';
-		snprintf(f.subtype, sizeof(f.subtype), "%s", pbeg);
+		i = sizeof(subtype);
+		snprintf(f.subtype, i, "%.*s", i - 1, pbeg);
 	}
 
 	xt_osf_parse_opt(f.opt, &f.opt_num, obuf, sizeof(obuf));
-- 
2.20.1


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

* Re: [PATCH iptables] nfnl_osf: fix snprintf -Wformat-truncation warning
  2019-07-21 19:24 [PATCH iptables] nfnl_osf: fix snprintf -Wformat-truncation warning Fernando Fernandez Mancera
@ 2019-07-23 19:26 ` Pablo Neira Ayuso
  2019-07-23 20:18   ` Fernando Fernandez Mancera
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-07-23 19:26 UTC (permalink / raw)
  To: Fernando Fernandez Mancera; +Cc: netfilter-devel

On Sun, Jul 21, 2019 at 09:24:15PM +0200, Fernando Fernandez Mancera wrote:
> Fedora 30 uses very recent gcc (version 9.1.1 20190503 (Red Hat 9.1.1-1)),
> osf produces following warnings:
> 
> -Wformat-truncation warning have been introduced in the version 7.1 of gcc.
> Also, remove a unneeded address check of "tmp + 1" in nf_osf_strchr().

nfnl_osf.c: In function ‘osf_load_line’:
nfnl_osf.c:372:14: error: ‘subtype’ undeclared (first use in this
function)
  372 |   i = sizeof(subtype);
      |              ^~~~~~~

Hitting this here after this patch.

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

* Re: [PATCH iptables] nfnl_osf: fix snprintf -Wformat-truncation warning
  2019-07-23 19:26 ` Pablo Neira Ayuso
@ 2019-07-23 20:18   ` Fernando Fernandez Mancera
  0 siblings, 0 replies; 3+ messages in thread
From: Fernando Fernandez Mancera @ 2019-07-23 20:18 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

El 23 de julio de 2019 21:26:43 CEST, Pablo Neira Ayuso <pablo@netfilter.org> escribió:
>On Sun, Jul 21, 2019 at 09:24:15PM +0200, Fernando Fernandez Mancera
>wrote:
>> Fedora 30 uses very recent gcc (version 9.1.1 20190503 (Red Hat
>9.1.1-1)),
>> osf produces following warnings:
>> 
>> -Wformat-truncation warning have been introduced in the version 7.1
>of gcc.
>> Also, remove a unneeded address check of "tmp + 1" in
>nf_osf_strchr().
>
>nfnl_osf.c: In function ‘osf_load_line’:
>nfnl_osf.c:372:14: error: ‘subtype’ undeclared (first use in this
>function)
>  372 |   i = sizeof(subtype);
>      |              ^~~~~~~
>
>Hitting this here after this patch.

I am sorry, this is a typo. It should be "f.subtype". I am going to send a v2. Sorry for the inconveniences.

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

end of thread, other threads:[~2019-07-23 20:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-21 19:24 [PATCH iptables] nfnl_osf: fix snprintf -Wformat-truncation warning Fernando Fernandez Mancera
2019-07-23 19:26 ` Pablo Neira Ayuso
2019-07-23 20:18   ` Fernando Fernandez Mancera

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).