]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Code cleanup to address a Coverity issue.
authorJohn Wolfe <jwolfe@vmware.com>
Wed, 19 Aug 2020 17:01:17 +0000 (10:01 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Wed, 19 Aug 2020 17:01:17 +0000 (10:01 -0700)
Coverity reports a "dereference after NULL check" in
BkdoorChannelStart.  However, at the point of dereference
it's known that chan->inStarted is TRUE, which means chan->in
is guaranteed to be non-NULL, so it's not a bug.

Still, given that an input channel, if present, must have been
started before calling BkdoorChannelStart, it's possible to do
some code cleanup that will also get Coverity to stop reporting
the issue.  Change what's currently a test into an ASSERT, test
chan->in rather than chan->inStarted, and add comments to make
it clearer what's going on.

open-vm-tools/lib/rpcChannel/bdoorChannel.c

index b153d52b21802227581cceeb02815ce32d143868..6144bf91912c5c5dd4f128e1b9c47536bf74b3fd 100644 (file)
@@ -54,19 +54,25 @@ typedef struct BackdoorChannel {
 static gboolean
 BkdoorChannelStart(RpcChannel *chan)
 {
-   gboolean ret = TRUE;
+   gboolean ret;
    BackdoorChannel *bdoor = chan->_private;
 
 #if defined(NEED_RPCIN)
-   ret = chan->in == NULL || chan->inStarted;
-   if (ret) {
-      ret = RpcOut_start(bdoor->out);
-      if (!ret) {
-         if (chan->inStarted) {
-            RpcIn_stop(chan->in);
-            chan->inStarted = FALSE;
-         }
-      }
+   /*
+    * If the RpcIn channel exists, it should have been started before
+    * calling this routine.
+    */
+   ASSERT(chan->in == NULL || chan->inStarted);
+
+   ret = RpcOut_start(bdoor->out);
+   if (!ret && chan->in != NULL) {
+      /*
+       * If the output channel failed to start, stop the input channel
+       * if there is one.
+       */
+
+      RpcIn_stop(chan->in);
+      chan->inStarted = FALSE;
    }
 #else
    ret = RpcOut_start(bdoor->out);