mirror of https://gitee.com/openkylin/libvirt.git
daemon: Resolve Coverity FORWARD_NULL
Coverity complains that the comparison: if (nfds && nfds > ((int)!!sock_path + (int)!!sock_path_ro)) could mean 'sock_path' is NULL. Later in virNetSocketNewListenUNIX there's a direct dereference of path in the error path: if (path[0] != '@') A bit of sleuthing proves that upon entry to daemonSetupNetworking there is no way for 'sock_path' to be NULL since daemonUnixSocketPaths will set up 'sock_file' (although it may not set up 'sock_file_ro') in all 3 paths. Adjusted code to add ATTRIBUTE_NONNULL(3) on incoming path parameter and then fixup the comparison of nfds to be a comparison against 2 or 1 depending on whether sock_path_ro is NULL or not.
This commit is contained in:
parent
3a0002b588
commit
1f96775866
|
@ -442,12 +442,13 @@ static void daemonInitialize(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int daemonSetupNetworking(virNetServerPtr srv,
|
static int ATTRIBUTE_NONNULL(3)
|
||||||
struct daemonConfig *config,
|
daemonSetupNetworking(virNetServerPtr srv,
|
||||||
const char *sock_path,
|
struct daemonConfig *config,
|
||||||
const char *sock_path_ro,
|
const char *sock_path,
|
||||||
bool ipsock,
|
const char *sock_path_ro,
|
||||||
bool privileged)
|
bool ipsock,
|
||||||
|
bool privileged)
|
||||||
{
|
{
|
||||||
virNetServerServicePtr svc = NULL;
|
virNetServerServicePtr svc = NULL;
|
||||||
virNetServerServicePtr svcRO = NULL;
|
virNetServerServicePtr svcRO = NULL;
|
||||||
|
@ -467,7 +468,7 @@ static int daemonSetupNetworking(virNetServerPtr srv,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nfds && nfds > ((int)!!sock_path + (int)!!sock_path_ro)) {
|
if (nfds > (sock_path_ro ? 2 : 1)) {
|
||||||
VIR_ERROR(_("Too many (%u) FDs passed from caller"), nfds);
|
VIR_ERROR(_("Too many (%u) FDs passed from caller"), nfds);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue