]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
ipblocklist-functions.pl: Abort and return code if a list is empty or
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 5 Mar 2022 09:01:24 +0000 (10:01 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 7 Jul 2022 15:26:13 +0000 (17:26 +0200)
not parse-able.

In case the downloaded list is empty or the parser is not able to parse
it properly, the download_and_create_blocklist() function now exits and
will return "empty_list" as new error code.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ipblocklist-functions.pl

index 6da371a004e8f1d830c471e59ec653217835b0ae..b6abb1befb6e18f3fb783478f8432f621ed20fa3 100644 (file)
@@ -91,6 +91,8 @@ sub get_ipset_db_file($) {
 ##   nothing - On success
 ##   not_modified - In case the servers responds with "Not modified" (304)
 ##   dl_error - If the requested blocklist could not be downloaded.
+##   empty_list - The downloaded blocklist is empty, or the parser was not able to parse
+##                it correctly.
 #
 sub download_and_create_blocklist($) {
        my ($list) = @_;
@@ -218,6 +220,13 @@ sub download_and_create_blocklist($) {
                push(@blocklist, $address);
        }
 
+       # Check if the content could be parsed correctly and the blocklist
+       # contains at least one item.
+       unless(@blocklist) {
+               # No entries - exit and return "empty_list".
+               return "empty_list";
+       }
+
        # Get amount of entries in the blocklist array.
        my $list_entries = scalar(@blocklist);