提交 1f967758 编写于 作者: J John Ferlan

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.
上级 3a0002b5
...@@ -442,12 +442,13 @@ static void daemonInitialize(void) ...@@ -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, ...@@ -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;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册