diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-06-16 01:00:00 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-06-16 01:37:14 +0200 |
commit | faf7bbc2d051f7351af5761e3f84f1c3c8b6479f (patch) | |
tree | 027dde053f3e55520554dc81576f1f86b9061386 /sysdeps | |
parent | 298a8b59d43cf9a75c44e9b2836e07282a6d34ed (diff) | |
download | glibc-faf7bbc2d051f7351af5761e3f84f1c3c8b6479f.tar.gz glibc-faf7bbc2d051f7351af5761e3f84f1c3c8b6479f.tar.xz glibc-faf7bbc2d051f7351af5761e3f84f1c3c8b6479f.zip |
hurd: Detect 32bit overflow in value returned by lseek
* sysdeps/mach/hurd/lseek.c: Include <errno.h>. * sysdeps/mach/hurd/lseek.c (__libc_lseek): Check that the value returned by __lseek64 can fit off_t, return EOVERFLOW otherwise.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/mach/hurd/lseek.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sysdeps/mach/hurd/lseek.c b/sysdeps/mach/hurd/lseek.c index 6677e01202..0a4077268a 100644 --- a/sysdeps/mach/hurd/lseek.c +++ b/sysdeps/mach/hurd/lseek.c @@ -17,12 +17,22 @@ #include <unistd.h> #include <sys/types.h> +#include <errno.h> /* Seek to OFFSET on FD, starting from WHENCE. */ off_t __libc_lseek (int fd, off_t offset, int whence) { - return __libc_lseek64 (fd, (off64_t) offset, whence); + off64_t res64 = __libc_lseek64 (fd, (off64_t) offset, whence); + off_t res = (off_t) res64; + + if (sizeof res != sizeof res64 && res != res64) + { + __set_errno (EOVERFLOW); + return (off_t) -1; + } + + return res; } weak_alias (__libc_lseek, __lseek) |