ipsets: allow blank/commented lines with loadfile
authorDaniel Harding <dharding@living180.net>
Tue, 27 Oct 2020 06:27:01 +0000 (09:27 +0300)
committerJo-Philipp Wich <jo@mein.io>
Sun, 6 Dec 2020 13:47:17 +0000 (14:47 +0100)
When loading ipset files using the loadfile option, skip blank lines and
lines that start with '#' (disregarding any leading whitespace).

Signed-off-by: Daniel Harding <dharding@living180.net>
ipsets.c

index 280845b9b7105c7aff6ec7b320cc647f01a7e775..ba31e645a8618a3ffaf481ac87d2daf9c5ad4b2a 100644 (file)
--- a/ipsets.c
+++ b/ipsets.c
@@ -16,6 +16,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <ctype.h>
+
 #include "ipsets.h"
 
 
@@ -337,6 +339,7 @@ load_file(struct fw3_ipset *ipset)
 {
        FILE *f;
        char line[128];
+       char *p;
 
        if (!ipset->loadfile)
                return;
@@ -350,8 +353,13 @@ load_file(struct fw3_ipset *ipset)
                return;
        }
 
-       while (fgets(line, sizeof(line), f))
-               fw3_pr("add %s %s", ipset->name, line);
+       while (fgets(line, sizeof(line), f)) {
+               p = line;
+               while (isspace(*p))
+                       p++;
+               if (*p && *p != '#')
+                       fw3_pr("add %s %s", ipset->name, line);
+       }
 
        fclose(f);
 }