This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid bogus -Wstringop-overflow for strncpy with _FORTIFY_SOURCE (PR 82646)
- From: Christophe Lyon <christophe dot lyon at linaro dot org>
- To: Jeff Law <law at redhat dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 7 Dec 2017 14:46:10 +0100
- Subject: Re: [PATCH] avoid bogus -Wstringop-overflow for strncpy with _FORTIFY_SOURCE (PR 82646)
- Authentication-results: sourceware.org; auth=none
- References: <1e65b499-e816-4709-8e58-f591dea6508a@gmail.com> <44752f7b-b4f5-4011-0ef8-f739f8c2e69b@redhat.com>
Hi Martin,
On 6 December 2017 at 00:51, Jeff Law <law@redhat.com> wrote:
> On 12/05/2017 04:47 PM, Martin Sebor wrote:
>> PR middle-end/82646 - bogus -Wstringop-overflow with
>> -D_FORTIFY_SOURCE=2 on strncpy with range to a member array,
>>
>> The bug points out a false positive in a call to strncpy() when
>> _FORTIFY_SOURCE is defined that doesn't exist otherwise.
>>
>> The problem is that __builtin_strncpy buffer overflow checking
>> is done along with the expansion of the intrinsic in one place
>> and __builtin___strncpy_chk is handled differently in another,
>> and the two are out of sync.
>>
>> The attached patch corrects the choice of arguments used for
>> overflow detection in __builtin___strncpy_chk and aligns
>> the diagnostics between the two intrinsics.
>>
>> Martin
>>
>> gcc-82646.diff
>>
>>
>> PR tree-optimization/82646 - bogus -Wstringop-overflow with -D_FORTIFY_SOURCE=2 on strncpy with range to a member array
>>
>> gcc/ChangeLog:
>>
>> PR tree-optimization/82646
>> * builtins.c (maybe_emit_chk_warning): Use size as the bound for
>> strncpy, not maxlen.
>>
>> gcc/testsuite/ChangeLog:
>>
>> PR tree-optimization/82646
>> * gcc.dg/builtin-stringop-chk-1.c: Adjust.
>> * gcc.dg/builtin-stringop-chk-9.c: New test.
> OK.
>
The new test fails on 32 bits platforms (arm, x86_32, aarch64 ilp32):
FAIL: gcc.dg/builtin-stringop-chk-9.c (test for warnings, line 125)
FAIL: gcc.dg/builtin-stringop-chk-9.c (test for warnings, line 133)
FAIL: gcc.dg/builtin-stringop-chk-9.c (test for warnings, line 141)
FAIL: gcc.dg/builtin-stringop-chk-9.c (test for warnings, line 149)
Christophe
> [ Happy to see something easy fly by that isn't SVE related :-) ]
>
> jeff