]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Detect 32bit overflow in value returned by lseek
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Fri, 15 Jun 2018 23:00:00 +0000 (01:00 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Fri, 15 Jun 2018 23:37:14 +0000 (01:37 +0200)
* 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.

ChangeLog
sysdeps/mach/hurd/lseek.c

index 74c14d4f84c67472e2e65ab930b04b65db631f02..0a2e082d73143da20a67e234b45665ccb8d7e95a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@
        of sendfile.
        * sysdeps/mach/hurd/sendfile64.c (sendfile64): Rename to __sendfile64.
        (sendfile64): New strong alias.
+       * 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.
 
 2018-06-15  Joseph Myers  <joseph@codesourcery.com>
 
index 6677e012023e8440e7c2a72828e0d771db4b0f75..0a4077268adeee4f5d5280ed67bbea223d879d94 100644 (file)
 
 #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)