From: Oliver Kurth Date: Tue, 12 Nov 2019 02:12:22 +0000 (-0800) Subject: Fix issues of unchecked return value reported by Coverity. X-Git-Tag: stable-11.1.0~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6286ea3908c85e829a8a4df7cf91ba62331a3942;p=thirdparty%2Fopen-vm-tools.git Fix issues of unchecked return value reported by Coverity. 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. --- diff --git a/open-vm-tools/libDeployPkg/linuxDeployment.c b/open-vm-tools/libDeployPkg/linuxDeployment.c index 3f86339bc..9a64cff70 100644 --- a/open-vm-tools/libDeployPkg/linuxDeployment.c +++ b/open-vm-tools/libDeployPkg/linuxDeployment.c @@ -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; } diff --git a/open-vm-tools/libDeployPkg/processPosix.c b/open-vm-tools/libDeployPkg/processPosix.c index 1caf6334f..cd99ce302 100644 --- a/open-vm-tools/libDeployPkg/processPosix.c +++ b/open-vm-tools/libDeployPkg/processPosix.c @@ -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;