diff options
author | Stefan Metzmacher <metze@samba.org> | 2017-12-20 08:25:19 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2017-12-22 10:05:07 +0100 |
commit | 3648ab02d4188f6441b83806faa79ae7c06bdb61 (patch) | |
tree | 479a512ccff63f4d2e5c8cf94a7affd5a0aa440a /source3/lib | |
parent | 7249bc196c46b950341f99f6d7ba9ce0173fcc94 (diff) | |
download | samba-3648ab02d4188f6441b83806faa79ae7c06bdb61.tar.gz |
g_lock: fix cleanup of stale entries in g_lock_trylock()
g_lock_trylock() always incremented the counter 'i', even after cleaning a stale
entry at position 'i', which means it skipped checking for a conflict against
the new entry at position 'i'.
As result a process could get a write lock, while there're still
some read lock holders. Once we get into that problem, also more than
one write lock are possible.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13195
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Wed Dec 20 20:31:48 CET 2017 on sn-devel-144
(similar to commit 576fb4fb5dc506bf55e5cf87973999dca444149b)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/g_lock.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 198fe563eb9..76b4af5d974 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -301,9 +301,11 @@ static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self, } } - for (i=0; i<num_locks; i++) { + i=0; + while (i < num_locks) { if (i == my_lock) { + i++; continue; } @@ -329,7 +331,9 @@ static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self, locks[i] = locks[num_locks-1]; num_locks -= 1; modified = true; + continue; } + i++; } if (my_lock >= num_locks) { |