summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-08-15 20:10:38 +0000
committerache <ache@FreeBSD.org>2001-08-15 20:10:38 +0000
commit9c95fc6cbe7cfdf59610fa796c6828737043865c (patch)
treed29af930221032c30f15dad72ba84a6df225095a /lib/libc
parent78c5ea3c24dc0dbddde7e16a3639dee878ca5bd4 (diff)
downloadFreeBSD-src-9c95fc6cbe7cfdf59610fa796c6828737043865c.zip
FreeBSD-src-9c95fc6cbe7cfdf59610fa796c6828737043865c.tar.gz
Use smarter overflow tests
Suggested by: bde
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/fseek.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c
index d311f7a..c357370 100644
--- a/lib/libc/stdio/fseek.c
+++ b/lib/libc/stdio/fseek.c
@@ -45,10 +45,11 @@ static const char rcsid[] =
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
+#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-#include <errno.h>
#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
@@ -132,7 +133,8 @@ _fseeko(fp, offset, whence)
} else if (fp->_flags & __SWR && fp->_p != NULL)
curoff += fp->_p - fp->_bf._base;
- if (offset > 0 && offset + (off_t)curoff < 0) {
+ /* curoff always >= 0 */
+ if (offset > 0 && curoff > OFF_MAX - offset) {
errno = EOVERFLOW;
return (EOF);
}
@@ -194,7 +196,8 @@ _fseeko(fp, offset, whence)
else {
if (_fstat(fp->_file, &st))
goto dumb;
- if (offset > 0 && st.st_size + offset < 0) {
+ /* st.st_size always >= 0 */
+ if (offset > 0 && st.st_size > OFF_MAX - offset) {
errno = EOVERFLOW;
return (EOF);
}
OpenPOWER on IntegriCloud