]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/lock: FileLock_IsLocked crashes
authorVMware, Inc <>
Thu, 22 Dec 2011 00:38:14 +0000 (16:38 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 22 Dec 2011 00:38:14 +0000 (16:38 -0800)
Don't mix signed and unsigned arithmetic...

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/file/file.c
open-vm-tools/lib/file/fileLockPrimitive.c

index 1a3271d0c48b53f334a97024fb88b32a284feb23..0a2aae766b529f167609a88759efa0697d99863b 100644 (file)
@@ -65,6 +65,7 @@
 #include "hostinfo.h"
 #include "hostType.h"
 #include "vm_atomic.h"
+#include "fileLock.h"
 
 #include "unicodeOperations.h"
 
 Bool
 File_Exists(ConstUnicode pathName)  // IN: May be NULL.
 {
+   if (pathName == NULL) {
+      Log("%s: NULL pathName\n", __FUNCTION__);
+   } else {
+      FileLock_IsLocked(pathName, NULL, NULL);
+   }
+
    return FileIO_IsSuccess(FileIO_Access(pathName, FILEIO_ACCESS_EXISTS));
 }
 
@@ -119,9 +126,7 @@ File_Exists(ConstUnicode pathName)  // IN: May be NULL.
 int
 File_UnlinkIfExists(ConstUnicode pathName)  // IN:
 {
-   int ret;
-
-   ret = FileDeletion(pathName, TRUE);
+   int ret = FileDeletion(pathName, TRUE);
 
    if (ret != 0) {
       ret = (ret == ENOENT) ? 0 : -1;
index 92977ccd2015949911a9e3704b6f142499d1722a..b9eb853439f7d5e396f5e9e47d19f60348a9800f 100644 (file)
@@ -1959,14 +1959,14 @@ FileLockIsLockedPortable(ConstUnicode lockDir,  // IN:
 
    numEntries = FileListDirectoryRobust(lockDir, &fileList);
 
-   if (numEntries == -1 && errno != ENOENT) {
+   if (numEntries == -1) {
       /*
        * If the lock directory doesn't exist, we should not count this
        * as an error.  This is expected if the file isn't locked.
        */
 
       if (err != NULL) {
-         *err = errno;
+         *err = (errno == ENOENT) ? 0 : errno;
       }
 
       return FALSE;
@@ -1982,6 +1982,7 @@ FileLockIsLockedPortable(ConstUnicode lockDir,  // IN:
    for (i = 0; i < numEntries; i++) {
       Unicode_Free(fileList[i]);
    }
+
    free(fileList);
 
    return isLocked;
@@ -2009,8 +2010,12 @@ Bool
 FileLockIsLocked(ConstUnicode pathName,  // IN:
                  int *err)               // OUT/OPT:
 {
-   Unicode lockBase = Unicode_Append(pathName, FILELOCK_SUFFIX);
    Bool isLocked;
+   Unicode lockBase;
+
+   ASSERT(pathName);
+
+   lockBase = Unicode_Append(pathName, FILELOCK_SUFFIX);
 
    if (File_SupportsMandatoryLock(pathName)) {
       isLocked = FileLockIsLockedMandatory(lockBase, err);