nwfilter: don't crash listing filters in unprivileged daemon

The unprivileged libvirtd does not support nwfilter config, by leaves the
driver active. It is supposed to result in all APIs being an effective
no-op, but several APIs rely on driver->nwfilters being non-NULL, or they
will reference a NULL pointer. Rather than adding checks for NULL in many
places, just make sure  driver->nwfilters is always initialized.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2017-12-05 16:39:05 +00:00
parent ab7a2fe230
commit 7993554f70

View File

@ -189,6 +189,8 @@ nwfilterStateInitialize(bool privileged,
/* remember that we are going to use firewalld */ /* remember that we are going to use firewalld */
driver->watchingFirewallD = (sysbus != NULL); driver->watchingFirewallD = (sysbus != NULL);
driver->privileged = privileged; driver->privileged = privileged;
if (!(driver->nwfilters = virNWFilterObjListNew()))
goto error;
if (!privileged) if (!privileged)
return 0; return 0;
@ -244,9 +246,6 @@ nwfilterStateInitialize(bool privileged,
goto error; goto error;
} }
if (!(driver->nwfilters = virNWFilterObjListNew()))
goto error;
if (virNWFilterObjListLoadAllConfigs(driver->nwfilters, driver->configDir) < 0) if (virNWFilterObjListLoadAllConfigs(driver->nwfilters, driver->configDir) < 0)
goto error; goto error;
@ -271,6 +270,7 @@ nwfilterStateInitialize(bool privileged,
virNWFilterIPAddrMapShutdown(); virNWFilterIPAddrMapShutdown();
err_free_driverstate: err_free_driverstate:
virNWFilterObjListFree(driver->nwfilters);
VIR_FREE(driver); VIR_FREE(driver);
return -1; return -1;
@ -349,13 +349,13 @@ nwfilterStateCleanup(void)
nwfilterDriverRemoveDBusMatches(); nwfilterDriverRemoveDBusMatches();
/* free inactive nwfilters */
virNWFilterObjListFree(driver->nwfilters);
VIR_FREE(driver->configDir); VIR_FREE(driver->configDir);
nwfilterDriverUnlock(); nwfilterDriverUnlock();
} }
/* free inactive nwfilters */
virNWFilterObjListFree(driver->nwfilters);
virMutexDestroy(&driver->lock); virMutexDestroy(&driver->lock);
VIR_FREE(driver); VIR_FREE(driver);