From: VMware, Inc <> Date: Thu, 22 Dec 2011 00:38:14 +0000 (-0800) Subject: lib/lock: FileLock_IsLocked crashes X-Git-Tag: 2011.12.20-562307~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=032c9b0e841df579ced0c74a4fd0cb6cc799ab2b;p=thirdparty%2Fopen-vm-tools.git lib/lock: FileLock_IsLocked crashes Don't mix signed and unsigned arithmetic... Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index 1a3271d0c..0a2aae766 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -65,6 +65,7 @@ #include "hostinfo.h" #include "hostType.h" #include "vm_atomic.h" +#include "fileLock.h" #include "unicodeOperations.h" @@ -95,6 +96,12 @@ 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; diff --git a/open-vm-tools/lib/file/fileLockPrimitive.c b/open-vm-tools/lib/file/fileLockPrimitive.c index 92977ccd2..b9eb85343 100644 --- a/open-vm-tools/lib/file/fileLockPrimitive.c +++ b/open-vm-tools/lib/file/fileLockPrimitive.c @@ -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);