]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix issues of unchecked return value reported by Coverity.
authorOliver Kurth <okurth@vmware.com>
Tue, 12 Nov 2019 02:12:22 +0000 (18:12 -0800)
committerOliver Kurth <okurth@vmware.com>
Tue, 12 Nov 2019 02:12:22 +0000 (18:12 -0800)
CID 80926 (#2 of 2): Unchecked return value (CHECKED_RETURN)
8. check_return: Calling ForkExecAndWaitCommand without checking return value

CID 80934 (#2 of 2): Unchecked return value from library (CHECKED_RETURN)
3. check_return: Calling lseek(pkgFd, 512L, 0) without checking return value.
This library function may fail and return an error code.

CID 80927 (#4 of 4): Unchecked return value from library (CHECKED_RETURN)
5. check_return: Calling fcntl(p->stdoutFd, 4, flags | 0x800) without
checking return value. This library function may fail and return an error
code.

open-vm-tools/libDeployPkg/linuxDeployment.c
open-vm-tools/libDeployPkg/processPosix.c

index 3f86339bcd35a1695d938bb791a58d0060948c9d..9a64cff70786282259d33add26d1eaf6e403bd36 100644 (file)
@@ -1094,7 +1094,11 @@ done:
                   "/bin/rm -rf %s",
                   cloudInitTmpDirPath);
          command[sizeof(command) - 1] = '\0';
-         ForkExecAndWaitCommand(command, false);
+         if (ForkExecAndWaitCommand(command, false) != 0) {
+            sLog(log_warning,
+                 "Error while removing temporary folder '%s'. (%s)\n",
+                 cloudInitTmpDirPath, strerror(errno));
+         }
       }
       sLog(log_error, "Setting generic error status in vmx.\n");
       SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_RUNNING,
@@ -1512,10 +1516,23 @@ ExtractZipPackage(const char* pkgName,
       close(pkgFd);
       return FALSE;;
    }
-   lseek(pkgFd, sizeof(VMwareDeployPkgHdr), 0);
-   while((rdCount = read(pkgFd, copyBuf, sizeof copyBuf)) > 0) {
+   if (lseek(pkgFd, sizeof(VMwareDeployPkgHdr), 0) == (off_t) -1) {
+      sLog(log_error,
+           "Failed to set the offset for the package file '%s'. (%s)\n",
+           pkgName, strerror(errno));
+      close(pkgFd);
+      close(zipFd);
+      ret = FALSE;
+      goto done;
+   }
+   while ((rdCount = read(pkgFd, copyBuf, sizeof copyBuf)) > 0) {
       if (write(zipFd, copyBuf, rdCount) < 0) {
-         sLog(log_warning, "write() failed.\n");
+         sLog(log_error, "Failed to write the zip file '%s'. (%s)\n", zipName,
+              strerror(errno));
+         close(pkgFd);
+         close(zipFd);
+         ret = FALSE;
+         goto done;
       }
    }
 
@@ -1543,6 +1560,12 @@ ExtractZipPackage(const char* pkgName,
    }
 
    Process_Destroy(h);
+done:
+   // Clean up the temporary zip file
+   if (remove(zipName) != 0) {
+      sLog(log_warning, "Failed to remove the temporary zip file '%s'. (%s)\n",
+           zipName, strerror(errno));
+   }
 
    return ret;
 }
index 1caf6334fa455d1712bebbf23a56e2546bba7a36..cd99ce3025cd7e3f5cfde4b5a4f1376d49f0a7b3 100644 (file)
@@ -196,11 +196,17 @@ Process_RunToComplete(ProcessHandle h, unsigned long timeoutSec)
 
    p->stdoutFd = stdout[0];
    flags = fcntl(p->stdoutFd, F_GETFL);
-   fcntl(p->stdoutFd, F_SETFL, flags | O_NONBLOCK);
+   if (fcntl(p->stdoutFd, F_SETFL, flags | O_NONBLOCK) == -1) {
+      p->log(log_warning, "Failed to set stdoutFd status flags, (%s)",
+             strerror(errno));
+   }
 
    p->stderrFd = stderr[0];
    flags = fcntl(p->stderrFd, F_GETFL);
-   fcntl(p->stderrFd, F_SETFL, flags | O_NONBLOCK);
+   if (fcntl(p->stderrFd, F_SETFL, flags | O_NONBLOCK) == -1) {
+      p->log(log_warning, "Failed to set stderrFd status flags, (%s)",
+             strerror(errno));
+   }
 
    elapsedTimeLoopSleeps = 0;