Detect off_t EOVERFLOW of start/end offsets calculations for adv. lock,

as POSIX require.
This commit is contained in:
Andrey A. Chernov 2001-08-23 07:42:40 +00:00
parent 5dc445bf4a
commit 69cc1d0d7f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=82172
2 changed files with 27 additions and 3 deletions

View File

@ -40,6 +40,7 @@
*/
#include "opt_compat.h"
#include <machine/limits.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/lock.h>
@ -303,8 +304,14 @@ fcntl(p, uap)
fdrop(fp, p);
return (error);
}
if (fl.l_whence == SEEK_CUR)
if (fl.l_whence == SEEK_CUR) {
if ((fl.l_start > 0 &&
fp->f_offset > OFF_MAX - fl.l_start) ||
(fl.l_start < 0 &&
fp->f_offset < OFF_MIN - fl.l_start))
return (EOVERFLOW);
fl.l_start += fp->f_offset;
}
switch (fl.l_type) {
case F_RDLCK:
@ -356,8 +363,14 @@ fcntl(p, uap)
fdrop(fp, p);
return (EINVAL);
}
if (fl.l_whence == SEEK_CUR)
if (fl.l_whence == SEEK_CUR) {
if ((fl.l_start > 0 &&
fp->f_offset > OFF_MAX - fl.l_start) ||
(fl.l_start < 0 &&
fp->f_offset < OFF_MIN - fl.l_start))
return (EOVERFLOW);
fl.l_start += fp->f_offset;
}
error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_GETLK,
&fl, F_POSIX);
fdrop(fp, p);

View File

@ -39,6 +39,7 @@
#include "opt_debug_lockf.h"
#include <machine/limits.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@ -105,6 +106,8 @@ lf_advlock(ap, head, size)
off_t start, end;
int error;
if (fl->l_len < 0)
return (EINVAL);
/*
* Convert the flock structure into a start and end.
*/
@ -120,6 +123,9 @@ lf_advlock(ap, head, size)
break;
case SEEK_END:
/* size always >= 0 */
if (fl->l_start > 0 && size > OFF_MAX - fl->l_start)
return (EOVERFLOW);
start = size + fl->l_start;
break;
@ -131,7 +137,12 @@ lf_advlock(ap, head, size)
if (fl->l_len == 0)
end = -1;
else {
end = start + fl->l_len - 1;
off_t oadd = fl->l_len - 1;
/* fl->l_len & start are non-negative */
if (oadd > OFF_MAX - start)
return (EOVERFLOW);
end = start + oadd;
if (end < start)
return (EINVAL);
}