]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
network: Log a more useful message on invalid prefix
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Mar 2022 15:15:00 +0000 (15:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Mar 2022 15:15:00 +0000 (15:15 +0000)
If loc_network_subnets is being called with some invalid input, we just
fail without logging a useful message or setting errno accordingly.

This is being changed with this patch.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/network.c

index b720a0a85a415472cf6e19944e20cf397868ca3a..0b469e24cb5947c935cb1d3b5f78491deaaccaf3 100644 (file)
@@ -315,8 +315,11 @@ LOC_EXPORT int loc_network_subnets(struct loc_network* network,
        unsigned int prefix = network->prefix + 1;
 
        // Check if the new prefix is valid
-       if (!loc_address_valid_prefix(&network->first_address, prefix))
-               return -1;
+       if (!loc_address_valid_prefix(&network->first_address, prefix)) {
+               ERROR(network->ctx, "Invalid prefix: %d\n", prefix);
+               errno = EINVAL;
+               return 1;
+       }
 
        // Create the first half of the network
        r = loc_network_new(network->ctx, subnet1, &network->first_address, prefix);