This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: sprintf warning on overlapping output
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: Jeff Law <law at redhat dot com>
- Cc: Bernd Edlinger <bernd at edlinger-online dot de>, Martin Sebor <msebor at redhat dot com>, "gcc\@gcc.gnu.org" <gcc at gcc dot gnu dot org>
- Date: Mon, 26 Sep 2016 17:20:14 +0200
- Subject: Re: sprintf warning on overlapping output
- Authentication-results: sourceware.org; auth=none
- References: <57E79CD9.2080903@edlinger-online.de> <3f8c14ef-59df-05b5-e30f-8eb7909406db@redhat.com>
* Jeff Law:
> On 09/25/2016 03:46 AM, Bernd Edlinger wrote:
>> Hi Martin,
>>
>> in the past I have seen (and fixed) code like
>>
>> sprintf(buf, "%s %d", buf, x);
>>
>> that may possibly work by chance, but usually
>> produces undefined results.
>>
>> Do you see a way to enhance the warning for cases
>> where the output buffer overlaps an input buffer?
> ISTM you really need strong PTA analysis here to nail down the
> pointers to a single object, then you can query their ranges and look
> for overlap.
We could detect this at run time in glibc with reasonable cost, I
think. We should probably introduce new symbol versions if we do
that, to avoid breaking existing applications needlessly.
Or we could make this well-defined because it is such a useful
extension.