]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix Coverity reported issue time of check to time of use (TOCTOU) in deployPkg
authorOliver Kurth <okurth@vmware.com>
Fri, 22 Nov 2019 22:52:34 +0000 (14:52 -0800)
committerOliver Kurth <okurth@vmware.com>
Fri, 22 Nov 2019 22:52:34 +0000 (14:52 -0800)
Change to call mkdir directly, then check and log the error.

open-vm-tools/libDeployPkg/mspackWrapper.c

index 5f2aff21ee67346bd72108188318d5754c961dfc..e3322d0919341b2ec04e0566da8583b61d6b92e8 100644 (file)
@@ -115,7 +115,6 @@ MspackWrapper_SetLogger(LogFunction log)
  **/
 unsigned int
 SetupPath (char* path) {
-   struct stat stats;
    char* token;
 
    // walk through the path (it employs in string replacement)
@@ -139,10 +138,10 @@ SetupPath (char* path) {
       sLog(log_debug, "Creating directory %s \n", path);
 #endif
 
-      // ignore if the directory exists
-      if (!((stat(path, &stats) == 0) && S_ISDIR(stats.st_mode))) {
-         // make directory and check error
-         if (mkdir(path, 0777) == -1) {
+      if (mkdir(path, 0777) == -1) {
+         struct stat stats;
+         // ignore if the directory exists
+         if (!((stat(path, &stats) == 0) && S_ISDIR(stats.st_mode))) {
             sLog(log_error, "Unable to create directory %s (%s)\n", path,
                  strerror(errno));
             return LINUXCAB_ERROR;