public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Martin Sebor <msebor@gmail.com>,
	Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] avoid folding snprintf calls with bounds > INT_MAX (PR 87096)
Date: Thu, 13 Dec 2018 18:14:00 -0000	[thread overview]
Message-ID: <4c49588d-9873-d030-2cb5-0e55c7b852ec@redhat.com> (raw)
In-Reply-To: <d7d45019-6446-df48-98dd-42a3fd0d35b2@gmail.com>

On 12/12/18 4:18 PM, Martin Sebor wrote:
> POSIX requires snprintf to fail with EOVERFLOW when the specified
> bound exceeds INT_MAX.  This requirement conflicts with the C
> requirements on valid calls to the function and isn't universally
> implemented (e.g., Glibc doesn't seem to follow it, and GCC has
> historically not paid heed to it either).  Nevertheless, there
> are implementations that do respect it (Solaris being one of
> them), and it seems that GCC should make a tricky situation
> even more treacherous for programmers by returning different
> values from some calls to the function than the library would.
> This is also what bug 87096 requests.  The patch also adds
> a warning that was missing from a subset of these troublesome
> calls.
> 
> The attached patch disables the snprintf constant folding and
> range optimization for calls to it and other related bounded
> functions when the bound is not known not to exceed INT_MAX.
> 
> Tested on x86_64-linux.
> 
> Martin
> 
> gcc-87096.diff
> 
> PR tree-optimization/87096 - Optimised snprintf is not POSIX conformant
> 
> gcc/ChangeLog:
> 
> 	PR rtl-optimization/87096
> 	* gimple-ssa-sprintf.c (sprintf_dom_walker::handle_gimple_call): Avoid
> 	folding calls whose bound may exceed INT_MAX.  Diagnose bound ranges
> 	that exceed the limit.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/87096
> 	* gcc.dg/tree-ssa/builtin-snprintf-4.c: New test.
OK
jeff

  reply	other threads:[~2018-12-13 18:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12 23:18 Martin Sebor
2018-12-13 18:14 ` Jeff Law [this message]
2018-12-17  9:23   ` Christophe Lyon
2018-12-17 18:12     ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4c49588d-9873-d030-2cb5-0e55c7b852ec@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).