]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virFirewallApply: Fix possible NULL dereference on error
authorPeter Krempa <pkrempa@redhat.com>
Fri, 5 Mar 2021 09:38:49 +0000 (10:38 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 5 Mar 2021 14:33:34 +0000 (15:33 +0100)
Commit bbc25f0d03d443efd35381463efc81b01cb6ae96 juggled around some
error reporting. Unfortunately virFirewallApply tries to report the
errno stored in the firewall object and we'd try to do that when the
firewall object is NULL too. Report EINVAL if 'firewall' is NULL.

Found by Coverity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/util/virfirewall.c

index c1b7d2268bbde717e7588eb0dab63515ff5379dd..0dc0cecd5355e1a72d246fa8cbfcf6d35ab07860 100644 (file)
@@ -766,8 +766,12 @@ virFirewallApply(virFirewallPtr firewall)
         goto cleanup;
     }
     if (!firewall || firewall->err) {
-        virReportSystemError(firewall->err, "%s",
-                             _("Unable to create rule"));
+        int err = EINVAL;
+
+        if (firewall)
+            err = firewall->err;
+
+        virReportSystemError(err, "%s", _("Unable to create rule"));
         goto cleanup;
     }