lkml.org 
[lkml]   [2014]   [Jan]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v3 1/6] locks: consolidate common code in the flock_to_posix_lock routines
Ugh, I screwed up one more when rewriting flock{64}_to_posix_lock, an
off-by-one error caused by not noticing that the "end" offset of a lock
is at start + len - 1, not start + len.

(So for example, a 1-byte lock starting at offset 5 is recorded as
(fl_start, fl_end) == (5, 5), not (5,6)....)

This actually causes "cthon -l" fails as it attempts a lock with
(start, len) == (1, OFFSET_MAX).

--b.

diff --git a/fs/locks.c b/fs/locks.c
index 9523b89..f017280 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -365,16 +365,17 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl,
fl->fl_start += l->l_start;
if (fl->fl_start < 0)
return -EINVAL;
- if (l->l_len > 0 && l->l_len - 1 > OFFSET_MAX - fl->fl_start)
- return -EOVERFLOW;
- if (fl->fl_start + l->l_len < 0)
- return -EINVAL;

/* POSIX-1996 leaves the case l->l_len < 0 undefined;
POSIX-2001 defines it. */
- if (l->l_len > 0)
+ if (l->l_len > 0) {
+ if (l->l_len - 1 > OFFSET_MAX - fl->fl_start)
+ return -EOVERFLOW;
fl->fl_end = fl->fl_start + l->l_len - 1;
- else if (l->l_len < 0) {
+
+ } else if (l->l_len < 0) {
+ if (fl->fl_start + l->l_len < 0)
+ return -EINVAL;
fl->fl_end = fl->fl_start - 1;
fl->fl_start += l->l_len;
} else

\
 
 \ /
  Last update: 2014-01-05 22:01    [W:0.106 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site