From patchwork Sat Jun 16 01:06:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 930292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-93298-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="QVb1QdnH"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 416zjS0Pzlz9s3q for ; Sat, 16 Jun 2018 11:07:23 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=mxhWG8lDn+SooOBzp5MNB0veRJKYhGb a1XYxEg2kSROYPl3vnyTP1bD6Md5BOvkIUT51mJz56rhGzxuocvCL5Kh3obBHNb5 oZCA1CZ/4M78USUTzIFacAWLB6ROB0mcDkA6pOzDAggbs68Ohxdt3GzeVeeJGMcl ssb2Y01XXbMI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=LuiN23pIDpDBdN9YQgGDqUkQMq8=; b=QVb1Q dnHwnE3XQKLkEFvmQFsfKk4iaqdPwWWyt0SLFrUG9H+BEbWrZ10vv96er6apB0Og ZH/YybzJ7N8dyzn9TSGxH7EoxdaNHMNoCn5eAxplu8J4QoYSP1zqajXPflha8end viq0ogtA3m7BYxQkjeLzCqqTDB22+mMz0Zh+Cw= 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-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@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 03:06:21 +0200 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> * 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)