From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66347 invoked by alias); 16 Jun 2018 01:06:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 66130 invoked by uid 89); 16 Jun 2018 01:06:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_NEUTRAL,URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault Subject: [hurd,commited 2/8] hurd: Detect 32bit overflow in value returned by lseek Date: Sat, 16 Jun 2018 01:06:00 -0000 Message-Id: <20180616010627.29577-2-samuel.thibault@ens-lyon.org> In-Reply-To: <20180616010627.29577-1-samuel.thibault@ens-lyon.org> References: <20180616010627.29577-1-samuel.thibault@ens-lyon.org> X-SW-Source: 2018-06/txt/msg00450.txt.bz2 * sysdeps/mach/hurd/lseek.c: Include . * sysdeps/mach/hurd/lseek.c (__libc_lseek): Check that the value returned by __lseek64 can fit off_t, return EOVERFLOW otherwise. --- ChangeLog | 3 +++ sysdeps/mach/hurd/lseek.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 74c14d4f84..0a2e082d73 100644 --- 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 . + * 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 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 #include +#include /* 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) -- 2.17.1