From patchwork Fri Oct 11 14:47:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1175254 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=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-510764-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IKP1eU0V"; 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 46qW5S6lyYz9sNx for ; Sat, 12 Oct 2019 01:47:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=qqH/JjXz9hRWYI0O8et2QCJNcW4ZxWG4ETvbhCBYGl7GwltrPLG5L MNU3A1eUaq3Cd/Yqb5sczJmKdQgvKiHMxlpNJG5p3fQBRGIDD+MKHI3RhdA+tceD X8Ylybqvz3P/lw8PVg8xZlO2rqilpF5GghxNPzSGxIiS/pg7PGHCDI= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=FxNXQEFI60Lvyuid0iE3gaLD16A=; b=IKP1eU0VadjN/a225SZB yFb1yMT5SJmYBrJAOH4NwM8OQZvi47MfA+XmDr4tiVUAyH2fQI69B3zBzoYY6JQe r7pxcXR3tLKfV44yH2ooRYfVnuEble0sT/D/bN/Me8Ju29LjoYf+P81PwQcxr+6k D+TAxvckmqeA8k9dHZ0j2QE= Received: (qmail 59490 invoked by alias); 11 Oct 2019 14:47:33 -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 59471 invoked by uid 89); 11 Oct 2019 14:47:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Oct 2019 14:47:29 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 51F97142F for ; Fri, 11 Oct 2019 07:47:28 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EDF683F68E for ; Fri, 11 Oct 2019 07:47:27 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Fix unchecked use of tree_to_uhwi in tree-ssa-strlen.c Date: Fri, 11 Oct 2019 15:47:26 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes r273783 introduced an unchecked use of tree_to_uhwi. This is tested by the SVE ACLE patches, but could potentially trigger in non-SVE cases too. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2019-10-11 Richard Sandiford gcc/ * tree-ssa-strlen.c (count_nonzero_bytes): Check tree_fits_uhwi_p before using tree_to_uhwi. Index: gcc/tree-ssa-strlen.c =================================================================== --- gcc/tree-ssa-strlen.c 2019-10-11 15:43:51.127514545 +0100 +++ gcc/tree-ssa-strlen.c 2019-10-11 15:46:11.718524445 +0100 @@ -4026,10 +4026,10 @@ count_nonzero_bytes (tree exp, unsigned /* The size of the MEM_REF access determines the number of bytes. */ tree type = TREE_TYPE (exp); - if (tree typesize = TYPE_SIZE_UNIT (type)) - nbytes = tree_to_uhwi (typesize); - else + tree typesize = TYPE_SIZE_UNIT (type); + if (!typesize || !tree_fits_uhwi_p (typesize)) return false; + nbytes = tree_to_uhwi (typesize); /* Handle MEM_REF = SSA_NAME types of assignments. */ return count_nonzero_bytes (arg, offset, nbytes, lenrange, nulterm,