From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 44327 invoked by alias); 10 Nov 2017 00:17:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 44314 invoked by uid 89); 10 Nov 2017 00:17:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: =?ISO-8859-1?Q?No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=and=c2, this=c2, work, of=c2?= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Nov 2017 00:17:28 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44BEDC056861; Fri, 10 Nov 2017 00:17:27 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-12.rdu2.redhat.com [10.10.112.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E1DE17970; Fri, 10 Nov 2017 00:17:25 +0000 (UTC) Subject: Re: [PATCH 3/4] enhance overflow and truncation detection in strncpy and strncat (PR 81117) To: Martin Sebor , Gcc Patch List References: <13944863-99a8-4144-1703-c6e1a2f36425@gmail.com> <0bbc91cd-fcdb-be61-e1d0-4b230f23b1a9@redhat.com> <4f4fbd4c-cb46-b80d-5749-ebb6bb050bc4@gmail.com> <62c4aa45-9bda-b2de-75b8-7d5f6c75df9c@redhat.com> <1ccbff03-b2df-7ac3-e0c5-d58bbc370891@redhat.com> From: Jeff Law Message-ID: Date: Fri, 10 Nov 2017 00:31:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00809.txt.bz2 On 11/09/2017 04:44 PM, Martin Sebor wrote: > Attached is another update to the patch with the above.  While > going through it again I noticed a couple of opportunities to > handle ranges so I added those as well.  I have retested the > patch with GDB and Glibc.  They both require minor changes and > I will submit patches with those once this work is checked in. > > Is this good enough to commit now? > > Martin > > gcc-81117.diff > > > PR c/81117 - Improve buffer overflow checking in strncpy > > ada/ChangeLog: > PR c/81117 > * adadecode.c (__gnat_decode): Use memcpy instead of strncpy. > * argv.c (__gnat_fill_env): Same. > > fortran/ChangeLog: > PR c/81117 > * decl.c (build_sym): Use memcpy instead of strncpy. > > gcc/ChangeLog: > > PR c/81117 > * builtins.c (compute_objsize): Handle arrays that > compute_builtin_object_size likes to fail for. Make extern. > * builtins.h (compute_objsize): Declare. > (check_strncpy_sizes): New function. > (expand_builtin_strncpy): Call check_strncpy_sizes. > * gimple-fold.c (gimple_fold_builtin_strncpy): Implement > -Wstringop-truncation. > (gimple_fold_builtin_strncat): Same. > * gimple.c (gimple_build_call_from_tree): Set call location. > * tree-ssa-strlen.c (strlen_to_stridx): New global variable. > (maybe_diag_bound_equal_length, is_strlen_related_p): New functions. > (handle_builtin_stxncpy, handle_builtin_strncat): Same. > (handle_builtin_strlen): Use strlen_to_stridx. > (strlen_optimize_stmt): Handle flavors of strncat, strncpy, and > stpncpy. > Use strlen_to_stridx. > (pass_strlen::execute): Release strlen_to_stridx. > * doc/invoke.texi (-Wsizeof-pointer-memaccess): Document enhancement. > (-Wstringop-truncation): Document new option. > > gcc/c-family/ChangeLog: > > PR c/81117 > * c-common.c (catenate_strings): Use memcpy instead of strncpy. > * c-warn.c (sizeof_pointer_memaccess_warning): Handle arrays. > * c.opt (-Wstringop-truncation): New option. > > gcc/objc/ChangeLog: > > PR c/81117 > * objc-encoding.c (encode_type): Use memcpy instead of strncpy. > > gcc/testsuite/ChangeLog: > > PR c/81117 > * c-c++-common/Wsizeof-pointer-memaccess3.c: New test. > * c-c++-common/Wstringop-overflow.c: Same. > * c-c++-common/Wstringop-truncation.c: Same. > * c-c++-common/Wsizeof-pointer-memaccess2.c: Adjust. > * c-c++-common/attr-nonstring-2.c: New test. > * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Adjust. > * g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same. > * gcc.dg/torture/pr63554.c: Same. > * gcc.dg/Walloca-1.c: Disable macro tracking. OK. Sorry for the long review cycles on this one. jeff