提交 0a8a79af 编写于 作者: E Eric Blake

rpc: avoid freeing uninitialized variable

Detected by Coverity.  Both are instances of bad things happening
if pipe2 fails; the virNetClientNew failure could free garbage,
and virNetSocketNewConnectCommand could close random fds.

Note: POSIX doesn't guarantee the contents of fd[0] and fd[1]
after pipe failure: http://austingroupbugs.net/view.php?id=467
We may need to introduce a virPipe2 wrapper that guarantees
that on pipe failure, the fds are explicitly set to -1, rather
than our current state of assuming the fds are unchanged from
their value prior to the failed pipe call.

* src/rpc/virnetclient.c (virNetClientNew): Initialize variable.
* src/rpc/virnetsocket.c (virNetSocketNewConnectCommand):
Likewise.
上级 cdb0e0dc
...@@ -113,7 +113,7 @@ static void virNetClientIncomingEvent(virNetSocketPtr sock, ...@@ -113,7 +113,7 @@ static void virNetClientIncomingEvent(virNetSocketPtr sock,
static virNetClientPtr virNetClientNew(virNetSocketPtr sock, static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
const char *hostname) const char *hostname)
{ {
virNetClientPtr client; virNetClientPtr client = NULL;
int wakeupFD[2] = { -1, -1 }; int wakeupFD[2] = { -1, -1 };
if (pipe2(wakeupFD, O_CLOEXEC) < 0) { if (pipe2(wakeupFD, O_CLOEXEC) < 0) {
......
...@@ -511,8 +511,8 @@ int virNetSocketNewConnectCommand(virCommandPtr cmd, ...@@ -511,8 +511,8 @@ int virNetSocketNewConnectCommand(virCommandPtr cmd,
virNetSocketPtr *retsock) virNetSocketPtr *retsock)
{ {
pid_t pid = 0; pid_t pid = 0;
int sv[2]; int sv[2] = { -1, -1 };
int errfd[2]; int errfd[2] = { -1, -1 };
*retsock = NULL; *retsock = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册