From patchwork Tue Sep 10 15:21:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 273915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 80BDC2C01E5 for ; Wed, 11 Sep 2013 01:21:48 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=GF6EWYnJyVF48Y94xL+9BVJL60t70JXYL0M474ULBxDZmjPYEo VDNC2kJ0z7/I7mxupW/s7vNB0soec+q73T5mcc3kwHe6DW0qiqETnR4Wr1V3PsTI BwGTplYmhRlljTLitGFHa34F/kSNrnff2pIBzWwrgwZ0veq4KKJfDPFrw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=2o77c9BoCf8MEbw2nlZN0V5LFn0=; b=WJWOXzcSmPov+GrOHgpr 4bPK+tgPJK68HP/my00z+7Ej0BsdTcH4DXGzfd/MymoGQVHJPk5AeAOMNl8Ba9F2 kw88u3io9keM/E1FdlcHZBjNLXyBmPZf0c1JcWIC5b+iGLPHhJj2/3G3ii74zREi sYS0XWrlQieg8BVRIU+LxiY= Received: (qmail 28240 invoked by alias); 10 Sep 2013 15:21:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 28230 invoked by uid 89); 10 Sep 2013 15:21:42 -0000 Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 10 Sep 2013 15:21:42 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=BAYES_05, RDNS_NONE autolearn=no version=3.3.2 X-HELO: rock.gnat.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 6B17111661E; Tue, 10 Sep 2013 11:21:51 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vy2Qmanp6wh6; Tue, 10 Sep 2013 11:21:51 -0400 (EDT) Received: from kwai.gnat.com (unknown [IPv6:2620:20:4000:0:a6ba:dbff:fe26:1f63]) by rock.gnat.com (Postfix) with ESMTP id 5937D11661C; Tue, 10 Sep 2013 11:21:51 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 8FEE23FB31; Tue, 10 Sep 2013 11:21:39 -0400 (EDT) Date: Tue, 10 Sep 2013 11:21:39 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Avoid reading past end of file when checking for BOM Message-ID: <20130910152139.GA22055@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) This patch makes sure that the routine Check_For_BOM cannot read past the end of file. In practice it is probably the case that this cannot cause a real error, but valgrind can see that this is happening. So this change will avoid the annoying false positive from valgrind. It's not worth setting up a valgrind test for this very minor issue, and there is no way to generate a real test that fails, so no test. Tested on x86_64-pc-linux-gnu, committed on trunk 2013-09-10 Robert Dewar * sinput.adb (Check_For_BOM): Avoid reading past end of file. Index: sinput.adb =================================================================== --- sinput.adb (revision 202451) +++ sinput.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2013, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -258,10 +258,20 @@ BOM : BOM_Kind; Len : Natural; Tst : String (1 .. 5); + C : Character; begin for J in 1 .. 5 loop - Tst (J) := Source (Scan_Ptr + Source_Ptr (J) - 1); + C := Source (Scan_Ptr + Source_Ptr (J) - 1); + + -- Definitely no BOM if EOF character marks either end of file, or + -- an illegal non-BOM character if not at the end of file. + + if C = EOF then + return; + end if; + + Tst (J) := C; end loop; Read_BOM (Tst, Len, BOM, False);