From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 54293 invoked by alias); 13 Dec 2016 23:49:23 -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 54176 invoked by uid 89); 13 Dec 2016 23:49:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: mail-qt0-f193.google.com Received: from mail-qt0-f193.google.com (HELO mail-qt0-f193.google.com) (209.85.216.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Dec 2016 23:49:12 +0000 Received: by mail-qt0-f193.google.com with SMTP id m48so327596qta.2 for ; Tue, 13 Dec 2016 15:49:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=m2qLPWeFKf6atGjZYKdf+z1lmLuvWHnXGVE1hSahGzg=; b=bEA01BxCyRTXzuGtvunQB72LaxsMR1zD7uckjmgEeIiV6Zrsd0MyEhgKdYFuryNbHp mB8t/FfdilQmwKq0wZeTC+MCgbDmSQo0SUdyDIHWqx2FYI0rQnCXOKeFEhK5yhoObjR3 rgQ3S7kZ7WKsoXCGIo9BXly0lFowKuDDENBdpnF34KJsr8jvr3UnMqv/4s7h6dZZIJgU at2NwIl0yWERagdDFg6iQD/IMfrjMF2N0tzTw20KDkuocEE2/oUmKjQAl98zLjHAfTuD iNY9+YzmTqF2wbaYond6TWOV6NmksGOCZe9tYoUCjeJGLRsHMBt7ERPrkHNaktTVq66t lMBg== X-Gm-Message-State: AKaTC03nMmPd8NIZSFq4GpGIDyOtPNCeoCH3DjhwuLi3TTjR4ZPjnk2ifIwRahPKh7PrYQ== X-Received: by 10.237.62.27 with SMTP id l27mr83201804qtf.34.1481672950729; Tue, 13 Dec 2016 15:49:10 -0800 (PST) Received: from [192.168.0.26] (97-124-188-210.hlrn.qwest.net. [97.124.188.210]) by smtp.gmail.com with ESMTPSA id r8sm30283623qtc.32.2016.12.13.15.49.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 15:49:10 -0800 (PST) Subject: Re: [PATCH] fix integer overflow bugs in gimple-ssa-sprintf.c (PR 78608) To: Gcc Patch List References: <7258e3eb-6942-faac-cbb3-80a4ee966521@gmail.com> From: Martin Sebor Message-ID: <96a035c4-19ab-ca12-78d0-7d8fe4d6218c@gmail.com> Date: Tue, 13 Dec 2016 23:49:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <7258e3eb-6942-faac-cbb3-80a4ee966521@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg01208.txt.bz2 Ping: https://gcc.gnu.org/ml/gcc-patches/2016-12/msg00262.html (I would have almost forgotten about this if it weren't for bug 78786. While working on a fix for it I keep thinking that some of the changes I'm making look like they should have already been made.) Thanks Martin On 12/02/2016 05:36 PM, Martin Sebor wrote: > Bug 78608 - gimple-ssa-sprintf.c:570:17: runtime error: negation > of -9223372036854775808 cannot be represented in type 'long int' > points out an integer overflow bug in the pass caught by ubsan. > The bug was due to negating a number without checking for equality > to INT_MIN. > > In addition, my recent change to fix 78521 introduced a call to > abs() that broke the Solaris bootstrap: > > https://gcc.gnu.org/ml/gcc-patches/2016-12/msg00161.html > > While fixing these two problems I noticed that the rest of the pass > wasn't handling the corner case of a width with the value of INT_MIN > specified via an argument to the asterisk, such as in: > > int n = snprintf(0, 0, "%*i", INT_MIN, 0); > > This is undefined behavior because negative width is supposed to be > treated as the left justification flag followed by a positive width > (thus resulting in INT_MAX + 1 bytes). This problem affected all > integer and floating point directives. > > Finally, while there, I decided to include in information messages > a bit of detail about ranges of floating point values that was > missing. I did this to help answer questions like those raised > earlier this week by Gerald here ("where does the 317 come from?): > > https://gcc.gnu.org/ml/gcc/2016-11/msg00102.html > > The attached patch adjusts the pass to handle these problems. > > Martin