From patchwork Thu Oct 13 09:23:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 681683 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3svlfc3Q0lz9t0J for ; Thu, 13 Oct 2016 20:24:07 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Eum9TToW; dkim-atps=neutral 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:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; q=dns; s=default; b=Y0mdEmStFfLODuV7 N36F0US2offMlqZUIqo40TI9YQ9OcxxpqFdiSDa8i84xk/VL7wq7bz8WAxwgVrJE k2R+KUpZY4rNrM9dWuBX3n3Uw3I/TDDxegGw05WNaSKihqPDQtbDf5fpYViDo3be A/tz8hdAUhtLCruPMacHHBnqda4= 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:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; s=default; bh=VguLLqX11pyDB4eGcoKIVx hhh20=; b=Eum9TToW9VWYQx8VcQu1xmzKmiQoXPUD3GjwXzqjbF55wy5/B7hMaZ bHkxMrdAHxmWu6KWbcvraOuEwJ2bO2FnwvOBGgTYdRlUluTFWJlTJjIhDFbFGsvZ K1J/15lxYoOsYuQOh79GeykmQJh4NxPv1GifP6NRsA1rJSX8Lem1E= Received: (qmail 49383 invoked by alias); 13 Oct 2016 09:23:57 -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 49338 invoked by uid 89); 13 Oct 2016 09:23:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=wint_t, terminating, H*r:Sun, Hx-languages-length:4911 X-HELO: smtp.CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE (HELO smtp.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Oct 2016 09:23:54 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 46E6B512; Thu, 13 Oct 2016 11:23:49 +0200 (CEST) Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id bm8I271h3GSo; Thu, 13 Oct 2016 11:23:45 +0200 (CEST) Received: from lokon.CeBiTec.Uni-Bielefeld.DE (lokon.CeBiTec.Uni-Bielefeld.DE [129.70.161.152]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id 6D01B50C; Thu, 13 Oct 2016 11:23:45 +0200 (CEST) Received: (from ro@localhost) by lokon.CeBiTec.Uni-Bielefeld.DE (8.15.2+Sun/8.15.2/Submit) id u9D9Nim0004055; Thu, 13 Oct 2016 11:23:44 +0200 (MEST) From: Rainer Orth To: Martin Sebor Cc: David Malcolm , Gcc Patch List , Joseph Myers , Jeff Law , Richard Biener , Jakub Jelinek , Bernd Schmidt , Manuel =?iso-8859-15?Q?L=F3pez-Ib=E1=F1ez?= , Florian Weimer Subject: Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905) References: <5776B33E.2080504@gmail.com> <578D512F.9050909@gmail.com> <9bb5ad66-4985-8c42-f800-4d84e0e18659@redhat.com> <57A3AFFF.7090109@gmail.com> <57AD30E5.3000801@gmail.com> <22a47656-c23c-4840-2e49-a59f4af513b1@redhat.com> <57B725F6.8000405@gmail.com> <110cfc6b-7856-9b51-885f-05402b14fc3e@redhat.com> <57D1B5F0.1030504@gmail.com> <57D60D03.7080601@gmail.com> <1474050251.6782.70.camel@redhat.com> <0a1c535f-f5a9-4bda-a598-a9af92e9e855@gmail.com> Date: Thu, 13 Oct 2016 11:23:44 +0200 In-Reply-To: <0a1c535f-f5a9-4bda-a598-a9af92e9e855@gmail.com> (Martin Sebor's message of "Tue, 4 Oct 2016 17:30:20 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes Hi Martin, >> as it happens, I'd already started bootstraps with your patch before >> your mail arrived :-) > > Thanks for your help getting to the bottom of this! > >> >> We're left with >> >> FAIL: gcc.dg/tree-ssa/builtin-sprintf-warn-1.c (test for excess errors) >> FAIL: gcc.dg/tree-ssa/builtin-sprintf-warn-4.c (test for excess errors) >> >> for 32 bit and >> >> FAIL: gcc.dg/tree-ssa/builtin-sprintf-warn-4.c (test for excess errors) >> >> for 64 bit on both i386-pc-solaris2.12 and sparc-sun-solaris2.12. >> >> In the 32-bit builtin-sprintf-warn-1.c case, there are many instances of >> >> Excess errors: >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c:224:3: >> warning: format '%lc' expects argument of type 'wint_t', but argument 5 >> has type 'int' [-Wformat=] > > I've built the sparc-sun-solaris2.12 toolchain and reproduced these > warnings. They are vestiges of those I saw and some of which I fixed > before. The problem is that %lc expects a wint_t argument which on > this target is an alias for long in but the argument of 0 has type > int. The warning is coming out of the -Wformat checker which doesn't > seem to care that int and long have the same size. I've committed > r240758 that should fix the remaining warnings of this kind but long > term I think GCC should change to avoid warning in this case (Clang > doesn't). > >> >> while the second is >> >> Excess errors: >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c:15:23: >> warning: writing a terminating nul past the end of the destination >> [-Wformat-length=]/vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c:30:21: >> warning: writing format character '4' at offset 3 past the end of the >> destination [-Wformat-length=] >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c:46:21: >> warning: writing format character '4' at offset 3 past the end of the >> destination [-Wformat-length=] >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c:61:25: >> warning: writing a terminating nul past the end of the destination >> [-Wformat-length=] >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c:74:22: >> warning: '%-s' directive writing 4 bytes into a region of size 1 >> [-Wformat-length=] >> >> I've no idea yet why in the first error message two different messages >> are joined into one line. Probably something with DejaGnu mangling the >> output... > > I've reproduced this as well and it took me a while to see the > problem. It turns out that the target specifier I used in the > test (*-*-*-*) happened to match my native target > x86_64-pc-linux-gnu but not sparc-sun-solaris2.12. Let me fix > that in the next patch. Hopefully with that all the remaining > failures should clear up. > > Thanks again for your help and patience! No worries: I've refreshed your patch on top of Thomas Preud'homme's for PR testsuite/77710 and found that one more bit is needed to fix this completely. 32-bit Solaris shows three more warnings: /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c:1355:3: warning: format '%lc' expects argument of type 'wint_t', but argument 6 has type 'int' [-Wformat=] /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c:1356:3: warning: format '%lc' expects argument of type 'wint_t', but argument 6 has type 'int' [-Wformat=] /vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c:1357:3: warning: format '%lc' expects argument of type 'wint_t', but argument 6 has type 'int' [-Wformat=] Fixed as follows: With this one and your refreshed patch, all failures are gone now for i386-pc-solaris2.12, sparc-sun-solaris2.12, and x86_64-pc-linux-gnu. Rainer # HG changeset patch # Parent 1aaf616a61b8ea3ecff9313e059a1e85571cdde1 [testsuite] Fix 32-bit gcc.dg/tree-ssa/builtin-sprintf-warn-1.c on Solaris diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c --- a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c @@ -1352,9 +1352,9 @@ void test_snprintf_chk_c_const (void) T (3, "%c_%c", '1', '2'); /* { dg-warning "output truncated" } */ /* Wide characters. */ - T (0, "%lc", 0); - T (1, "%lc", 0); - T (2, "%lc", 0); + T (0, "%lc", (wint_t)0); + T (1, "%lc", (wint_t)0); + T (2, "%lc", (wint_t)0); /* The following could result in as few as a single byte and in as many as MB_CUR_MAX, but since the MB_CUR_MAX value is a runtime property