]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: among: Check call to fstat()
authorPhil Sutter <phil@nwl.cc>
Thu, 5 Dec 2019 15:35:51 +0000 (16:35 +0100)
committerPhil Sutter <phil@nwl.cc>
Fri, 6 Dec 2019 11:12:08 +0000 (12:12 +0100)
If this fails, a bogus length value may be passed to mmap().

Fixes: 26753888720d8 ("nft: bridge: Rudimental among extension support")
extensions/libebt_among.c

index 2e87db3bc06faa8fae4e3dcd454dd23af3afc015..715d559f432c222250ee3038c67529fc1ebf3c2e 100644 (file)
@@ -6,6 +6,7 @@
  * August, 2003
  */
 
+#include <errno.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -137,7 +138,10 @@ static int bramong_parse(int c, char **argv, int invert,
                if ((fd = open(optarg, O_RDONLY)) == -1)
                        xtables_error(PARAMETER_PROBLEM,
                                      "Couldn't open file '%s'", optarg);
-               fstat(fd, &stats);
+               if (fstat(fd, &stats) < 0)
+                       xtables_error(PARAMETER_PROBLEM,
+                                     "fstat(%s) failed: '%s'",
+                                     optarg, strerror(errno));
                flen = stats.st_size;
                /* use mmap because the file will probably be big */
                optarg = mmap(0, flen, PROT_READ | PROT_WRITE,