From 7e65e1b5a9a7bdaa7ca28bc5c1773bc5472f19af Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Fri, 10 Jul 2015 12:40:24 +0530 Subject: locks: Handle negative values for flock->l_len MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As per 'man 3 fcntl', "If l_len is positive, the area affected shall start at l_start and end at l_start+l_len−1. If l_len is negative, the area affected shall start at l_start+l_len and end at l_start−1. Locks may start and extend beyond the current end of a file, but shall not extend before the beginning of the file." Currently we return EINVAL if l_len is found to be negative. Fixed the same as mentioned in the man page. This is backport of the below patch - http://review.gluster.org/11613 Change-Id: I493ce202c543185fc4ae7266d1aaf9d7e2a66991 BUG: 1312200 Signed-off-by: Soumya Koduri Reviewed-on: http://review.gluster.org/11613 Reviewed-by: Kaleb KEITHLEY Reviewed-by: Niels de Vos Reviewed-by: Raghavendra G Reviewed-on: http://review.gluster.org/13526 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System --- xlators/features/locks/src/posix.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'xlators') diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index 7dca2d0cb5f..3d79c570bb0 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -1811,12 +1811,23 @@ pl_lk (call_frame_t *frame, xlator_t *this, posix_lock_t *conf = NULL; int ret = 0; - if ((flock->l_start < 0) || (flock->l_len < 0)) { + if ((flock->l_start < 0) || + ((flock->l_start + flock->l_len) < 0)) { op_ret = -1; op_errno = EINVAL; goto unwind; } + /* As per 'man 3 fcntl', the value of l_len may be + * negative. In such cases, lock request should be + * considered for the range starting at 'l_start+l_len' + * and ending at 'l_start-1'. Update the fields accordingly. + */ + if (flock->l_len < 0) { + flock->l_start += flock->l_len; + flock->l_len = abs (flock->l_len); + } + pl_inode = pl_inode_get (this, fd->inode); if (!pl_inode) { op_ret = -1; -- cgit