ipblocklist-functions.pl: Abort and return code if a list is empty or

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>
This commit is contained in:
Stefan Schantl
2022-03-05 10:01:24 +01:00
parent 0a4f60f28c
commit d7dd565341

View 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);