changeset 17468:aac4f4b886d2

lib: Fixed file_dotlock_replace(flags=DOTLOCK_REPLACE_FLAG_VERIFY_OWNER|DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) The verification check failed because fd was already set to -1 by that time. Found by Coverity
author Timo Sirainen <tss@iki.fi>
date Fri, 13 Jun 2014 01:02:48 +0300
parents 899cf87a687c
children 54f1beb8d071
files src/lib/file-dotlock.c
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/file-dotlock.c	Fri Jun 13 00:57:06 2014 +0300
+++ b/src/lib/file-dotlock.c	Fri Jun 13 01:02:48 2014 +0300
@@ -855,22 +855,25 @@
 {
 	struct dotlock *dotlock;
 	const char *lock_path;
+	bool is_locked;
 
 	dotlock = *dotlock_p;
 	*dotlock_p = NULL;
 
+	is_locked = (flags & DOTLOCK_REPLACE_FLAG_VERIFY_OWNER) == 0 ? TRUE :
+		file_dotlock_is_locked(dotlock);
+
 	if ((flags & DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) != 0)
 		dotlock->fd = -1;
 
-	lock_path = file_dotlock_get_lock_path(dotlock);
-	if ((flags & DOTLOCK_REPLACE_FLAG_VERIFY_OWNER) != 0 &&
-	    !file_dotlock_is_locked(dotlock)) {
+	if (!is_locked) {
 		dotlock_replaced_warning(dotlock, FALSE);
 		errno = EEXIST;
 		file_dotlock_free(&dotlock);
 		return 0;
 	}
 
+	lock_path = file_dotlock_get_lock_path(dotlock);
 	if (rename(lock_path, dotlock->path) < 0) {
 		i_error("rename(%s, %s) failed: %m", lock_path, dotlock->path);
 		if (errno == ENOENT)