From ae536f753fae9ffcdf168efe662edce7ed1d05c5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 26 Feb 2014 16:30:25 -0800 Subject: [PATCH] s3: smbd: Ensure brl_get_locks_readonly() always returns a valid struct byte_range_lock even if there are no locks. brl_get_locks_readonly() currently returns NULL when it can't find any byte range locks on the file. This is an error - it should return a valid struct byte_range_lock containing num_locks == 0 so it can be cached. Returning NULL when there are no locks causes POSIX lock tests to fail returning NT_STATUS_NO_MEMORY (as it thinks it can't allocate the struct) instead of NT_STATUS_OK. Fixes bug: Bug 10431 - STATUS_NO_MEMORY response from Query File Posix Lock request https://bugzilla.samba.org/show_bug.cgi?id=10431 Signed-off-by: Jeremy Allison --- source3/locking/brlock.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index a516b60..e6c8949 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -2154,7 +2154,21 @@ struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp) make_tdb_data((uint8_t *)&fsp->file_id, sizeof(fsp->file_id)), brl_get_locks_readonly_parser, &state); - if (!NT_STATUS_IS_OK(status)) { + + if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_FOUND)) { + /* + * No locks on this file. Return an empty br_lock. + */ + br_lock = talloc(fsp, struct byte_range_lock); + if (br_lock == NULL) { + goto fail; + } + + br_lock->have_read_oplocks = false; + br_lock->num_locks = 0; + br_lock->lock_data = NULL; + + } else if (!NT_STATUS_IS_OK(status)) { DEBUG(3, ("Could not parse byte range lock record: " "%s\n", nt_errstr(status))); goto fail; -- 1.9.0.rc1.175.g0b1dcb5