]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
utils: nfnl_osf: fix snprintf -Wformat-truncation warning
authorFernando Fernandez Mancera <ffmancera@riseup.net>
Wed, 24 Jul 2019 07:31:14 +0000 (09:31 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 25 Jul 2019 09:33:06 +0000 (11:33 +0200)
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:346:33: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 128 [-Wformat-truncation=]
  346 |   snprintf(obuf, sizeof(obuf), "%s,", pbeg);
      |                                 ^~
nfnl_osf.c:346:3: note: ‘snprintf’ output between 2 and 1025 bytes into a
destination of size 128
  346 |   snprintf(obuf, sizeof(obuf), "%s,", pbeg);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nfnl_osf.c:354:40: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 32 [-Wformat-truncation=]
  354 |    snprintf(f.genre, sizeof(f.genre), "%s", pbeg);
      |                                        ^~
nfnl_osf.c:354:4: note: ‘snprintf’ output between 1 and 1024 bytes into a
destination of size 32
  354 |    snprintf(f.genre, sizeof(f.genre), "%s", pbeg);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nfnl_osf.c:363:43: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 32 [-Wformat-truncation=]
  363 |   snprintf(f.version, sizeof(f.version), "%s", pbeg);
      |                                           ^~
nfnl_osf.c:363:3: note: ‘snprintf’ output between 1 and 1024 bytes into a
destination of size 32
  363 |   snprintf(f.version, sizeof(f.version), "%s", pbeg);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nfnl_osf.c:370:47: warning: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 32 [-Wformat-truncation=]
  370 |       snprintf(f.subtype, sizeof(f.subtype), "%s", pbeg);
      |                                               ^~
nfnl_osf.c:370:7: note: ‘snprintf’ output between 1 and 1024 bytes into a
destination of size 32
  370 |       snprintf(f.subtype, sizeof(f.subtype), "%s", pbeg);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
utils/nfnl_osf.c

index 0ea33fce960fe89a6519752ef1d4b3c0cc7bf3ec..15d531975e11d073dad690f1e120e365ab6f1cc6 100644 (file)
@@ -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(f.subtype);
+               snprintf(f.subtype, i, "%.*s", i - 1, pbeg);
        }
 
        xt_osf_parse_opt(f.opt, &f.opt_num, obuf, sizeof(obuf));