]> git.ipfire.org Git - network.git/commitdiff
ports: Don't crash with an assertion error when no hook can be found
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Jun 2017 18:26:08 +0000 (19:26 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Jun 2017 18:28:00 +0000 (19:28 +0100)
This happens when a device has an empty configuration file or
the HOOK variable is not set for an other reason.

In that case the function make the entire program crash.

This patch changes behaviour in that sense that the function
returns with an error which must be evaluated by the calling
function.

Fixes #11400

Reported-by: Daniel Weismüller <daniel.weismueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.ports

index 40f4eaea6ebf4d39c078d6b6970a88de3bd98b0f..952eef9ba7c68dff1a37c623f05bf34711bd9456 100644 (file)
@@ -256,7 +256,11 @@ port_cmd() {
 
        local hook=$(port_get_hook ${port})
 
-       assert isset hook
+       # Abort if we could not find a hook
+       if ! isset hook; then
+               log CRITICAL "Port ${port} does not have a hook associated with it"
+               return ${EXIT_ERROR}
+       fi
 
        hook_exec port ${hook} ${cmd} ${port} $@
 }