dovecot-2.2: lib: Fixed file_dotlock_replace(flags=DOTLOCK_REPLA...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 12 23:20:42 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/aac4f4b886d2
changeset: 17468:aac4f4b886d2
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 13 01:02:48 2014 +0300
description:
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

diffstat:

 src/lib/file-dotlock.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (32 lines):

diff -r 899cf87a687c -r aac4f4b886d2 src/lib/file-dotlock.c
--- 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)


More information about the dovecot-cvs mailing list