From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: libc-alpha@sourceware.org
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
Subject: [hurd,commited 2/8] hurd: Detect 32bit overflow in value returned by lseek
Date: Sat, 16 Jun 2018 01:06:00 -0000 [thread overview]
Message-ID: <20180616010627.29577-2-samuel.thibault@ens-lyon.org> (raw)
In-Reply-To: <20180616010627.29577-1-samuel.thibault@ens-lyon.org>
* 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 | 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 <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>
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)
--
2.17.1
next prev parent reply other threads:[~2018-06-16 1:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-16 1:06 [hurd,commited 1/8] hurd: avoid PLT ref between sendfile and sendfile64 Samuel Thibault
2018-06-16 1:06 ` [hurd,commited 4/8] hurd: Avoid missing PLT ref from ld.so requirement Samuel Thibault
2018-06-16 1:06 ` Samuel Thibault [this message]
2018-06-16 1:06 ` [hurd,commited 8/8] hurd: Whitelist PLT refs which are difficult to avoid Samuel Thibault
2018-06-16 1:06 ` [hurd,commited 6/8] hurd: Avoid PLT ref to __mach_msg Samuel Thibault
2018-06-16 1:06 ` [hurd,commited 5/8] hurd: Avoid PLT references to shortcuts Samuel Thibault
2018-06-16 1:06 ` [hurd,commited 7/8] hurd: Avoid PLT references to syscalls Samuel Thibault
2018-06-16 1:15 ` [hurd,commited 3/8] hurd: Avoid PLT ref for __pthread_get_cleanup_stack Samuel Thibault
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180616010627.29577-2-samuel.thibault@ens-lyon.org \
--to=samuel.thibault@ens-lyon.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).