diff mbox series

string: Fix tester build with fortify enable with gcc < 12

Message ID 20230809120344.1095219-1-bmahi496@linux.ibm.com
State New
Headers show
Series string: Fix tester build with fortify enable with gcc < 12 | expand

Commit Message

develop--- via Libc-alpha Aug. 9, 2023, 12:03 p.m. UTC
From: Mahesh Bodapati <bmahi496@linux.ibm.com>

When building with fortify enabled, GCC < 12 issues a warning on the
fortify strncat wrapper might overflow the destination buffer.  However,
GCC does not provide a specific flag to disable the warning (the
failure is tied to -Werror). So to avoid disable all errors, only
enable the check for GCC 12 or newer.

Checked on ppc64 and x86_64.
---
 string/tester.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Rajalakshmi Srinivasaraghavan Aug. 9, 2023, 1:40 p.m. UTC | #1
On 8/9/23 7:03 AM, bmahi496@linux.ibm.com wrote:
> From: Mahesh Bodapati <bmahi496@linux.ibm.com>
>
> When building with fortify enabled, GCC < 12 issues a warning on the
> fortify strncat wrapper might overflow the destination buffer.  However,
> GCC does not provide a specific flag to disable the warning (the
> failure is tied to -Werror). So to avoid disable all errors, only
> enable the check for GCC 12 or newer.
>
> Checked on ppc64 and x86_64.
> ---
>   string/tester.c | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/string/tester.c b/string/tester.c
> index f7d4bac5a8..cf3f5ae495 100644
> --- a/string/tester.c
> +++ b/string/tester.c
> @@ -421,6 +421,12 @@ test_strncat (void)
>     (void) strncat (one, "ij", (size_t)-1);	/* set sign bit in count */
>     equal (one, "abcdghij", 13);
>   
> +  /* When building with fortify enabled, GCC < 12 issues a warning on the
> +     fortify strncat wrapper might overflow the destination buffer.  However,
> +     GCC does not provide a specific flag to disable the warning (the
> +     failure is tied to -Werror). So to avoid disable all errors, only
> +     enable the check for GCC 12 or newer.  */
> +#if __GNUC_PREREQ (12, 0)

Is it  possible to include a check for fortify enabled option ?

>     int ntest = 14;
>     char buf1[80] __attribute__ ((aligned (16)));
>     char buf2[32] __attribute__ ((aligned (16)));
> @@ -464,6 +470,7 @@ test_strncat (void)
>   		    }
>   		}
>   	  }
> +#endif
>   }
>   
>   static void
MAHESH BODAPATI Aug. 9, 2023, 2:50 p.m. UTC | #2
On 09/08/23 7:10 pm, Rajalakshmi Srinivasaraghavan wrote:
>
> On 8/9/23 7:03 AM, bmahi496@linux.ibm.com wrote:
>> From: Mahesh Bodapati <bmahi496@linux.ibm.com>
>>
>> When building with fortify enabled, GCC < 12 issues a warning on the
>> fortify strncat wrapper might overflow the destination buffer. However,
>> GCC does not provide a specific flag to disable the warning (the
>> failure is tied to -Werror). So to avoid disable all errors, only
>> enable the check for GCC 12 or newer.
>>
>> Checked on ppc64 and x86_64.
>> ---
>>   string/tester.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/string/tester.c b/string/tester.c
>> index f7d4bac5a8..cf3f5ae495 100644
>> --- a/string/tester.c
>> +++ b/string/tester.c
>> @@ -421,6 +421,12 @@ test_strncat (void)
>>     (void) strncat (one, "ij", (size_t)-1);    /* set sign bit in 
>> count */
>>     equal (one, "abcdghij", 13);
>>   +  /* When building with fortify enabled, GCC < 12 issues a warning 
>> on the
>> +     fortify strncat wrapper might overflow the destination buffer.  
>> However,
>> +     GCC does not provide a specific flag to disable the warning (the
>> +     failure is tied to -Werror). So to avoid disable all errors, only
>> +     enable the check for GCC 12 or newer.  */
>> +#if __GNUC_PREREQ (12, 0)
>
> Is it  possible to include a check for fortify enabled option ?

__USE_FORTIFY_LEVEL is 0 if fortify not enabled.

I will include it in the condition and share the updated patch.


>
>>     int ntest = 14;
>>     char buf1[80] __attribute__ ((aligned (16)));
>>     char buf2[32] __attribute__ ((aligned (16)));
>> @@ -464,6 +470,7 @@ test_strncat (void)
>>               }
>>           }
>>         }
>> +#endif
>>   }
>>     static void
Joseph Myers Aug. 9, 2023, 9:34 p.m. UTC | #3
On Wed, 9 Aug 2023, bmahi496--- via Libc-alpha wrote:

> From: Mahesh Bodapati <bmahi496@linux.ibm.com>
> 
> When building with fortify enabled, GCC < 12 issues a warning on the
> fortify strncat wrapper might overflow the destination buffer.  However,
> GCC does not provide a specific flag to disable the warning (the
> failure is tied to -Werror). So to avoid disable all errors, only
> enable the check for GCC 12 or newer.

What is the exact diagnostic message?
MAHESH BODAPATI Aug. 10, 2023, 7:09 a.m. UTC | #4
On 10/08/23 3:04 am, Joseph Myers wrote:
> On Wed, 9 Aug 2023, bmahi496--- via Libc-alpha wrote:
>
>> From: Mahesh Bodapati<bmahi496@linux.ibm.com>
>>
>> When building with fortify enabled, GCC < 12 issues a warning on the
>> fortify strncat wrapper might overflow the destination buffer.  However,
>> GCC does not provide a specific flag to disable the warning (the
>> failure is tied to -Werror). So to avoid disable all errors, only
>> enable the check for GCC 12 or newer.
> What is the exact diagnostic message?

The error looks like below .

/In file included from ../include/bits/string_fortified.h:1,//
//                 from ../string/string.h:548,//
//                 from ../include/string.h:60,//
//                 from tester.c:41,//
//                 from inl-tester.c:6://
//In function 'strncat',//
//    inlined from 'test_strncat' at tester.c:446:13://
//../string/bits/string_fortified.h:138:10:*error: '__builtin_strncat' 
specified bound [18446744073709551600, 18446744073709551615] exceeds 
maximum object size 9223372036854775807 [-Werror=stringop-overread]*//
//  138 |   return __builtin___strncat_chk (__dest, __src, __len,//
//      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//  139 |                                   __glibc_objsize (__dest));//
//      | ~~~~~~~~~~~~~~~~~~~~~~~~~/


>
Joseph Myers Aug. 10, 2023, 2:33 p.m. UTC | #5
On Thu, 10 Aug 2023, MAHESH BODAPATI wrote:

> On 10/08/23 3:04 am, Joseph Myers wrote:
> > On Wed, 9 Aug 2023, bmahi496--- via Libc-alpha wrote:
> > 
> > > From: Mahesh Bodapati<bmahi496@linux.ibm.com>
> > > 
> > > When building with fortify enabled, GCC < 12 issues a warning on the
> > > fortify strncat wrapper might overflow the destination buffer.  However,
> > > GCC does not provide a specific flag to disable the warning (the
> > > failure is tied to -Werror). So to avoid disable all errors, only
> > > enable the check for GCC 12 or newer.
> > What is the exact diagnostic message?
> 
> The error looks like below .
> 
> /In file included from ../include/bits/string_fortified.h:1,//
> //                 from ../string/string.h:548,//
> //                 from ../include/string.h:60,//
> //                 from tester.c:41,//
> //                 from inl-tester.c:6://
> //In function 'strncat',//
> //    inlined from 'test_strncat' at tester.c:446:13://
> //../string/bits/string_fortified.h:138:10:*error: '__builtin_strncat'
> specified bound [18446744073709551600, 18446744073709551615] exceeds maximum
> object size 9223372036854775807 [-Werror=stringop-overread]*//

Thanks.  Does it not work to disable -Wstringop-overread with the macros 
from libc-diag.h (moving the existing

#if __GNUC_PREREQ (11, 0)
DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overread");
#endif

to be alongside the existing -Wstringop-truncation disabling if it needs 
to be in effect before string.h is included)?
MAHESH BODAPATI Aug. 11, 2023, 1:34 p.m. UTC | #6
On 10/08/23 8:03 pm, Joseph Myers wrote:
> On Thu, 10 Aug 2023, MAHESH BODAPATI wrote:
>
>> On 10/08/23 3:04 am, Joseph Myers wrote:
>>> On Wed, 9 Aug 2023, bmahi496--- via Libc-alpha wrote:
>>>
>>>> From: Mahesh Bodapati<bmahi496@linux.ibm.com>
>>>>
>>>> When building with fortify enabled, GCC < 12 issues a warning on the
>>>> fortify strncat wrapper might overflow the destination buffer.  However,
>>>> GCC does not provide a specific flag to disable the warning (the
>>>> failure is tied to -Werror). So to avoid disable all errors, only
>>>> enable the check for GCC 12 or newer.
>>> What is the exact diagnostic message?
>> The error looks like below .
>>
>> /In file included from ../include/bits/string_fortified.h:1,//
>> //                 from ../string/string.h:548,//
>> //                 from ../include/string.h:60,//
>> //                 from tester.c:41,//
>> //                 from inl-tester.c:6://
>> //In function 'strncat',//
>> //    inlined from 'test_strncat' at tester.c:446:13://
>> //../string/bits/string_fortified.h:138:10:*error: '__builtin_strncat'
>> specified bound [18446744073709551600, 18446744073709551615] exceeds maximum
>> object size 9223372036854775807 [-Werror=stringop-overread]*//
> Thanks.  Does it not work to disable -Wstringop-overread with the macros
> from libc-diag.h (moving the existing
>
> #if __GNUC_PREREQ (11, 0)
> DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overread");
> #endif
>
> to be alongside the existing -Wstringop-truncation disabling if it needs
> to be in effect before string.h is included)?


Thanks, It's working.I will share the updated patch.


>
diff mbox series

Patch

diff --git a/string/tester.c b/string/tester.c
index f7d4bac5a8..cf3f5ae495 100644
--- a/string/tester.c
+++ b/string/tester.c
@@ -421,6 +421,12 @@  test_strncat (void)
   (void) strncat (one, "ij", (size_t)-1);	/* set sign bit in count */
   equal (one, "abcdghij", 13);
 
+  /* When building with fortify enabled, GCC < 12 issues a warning on the
+     fortify strncat wrapper might overflow the destination buffer.  However,
+     GCC does not provide a specific flag to disable the warning (the
+     failure is tied to -Werror). So to avoid disable all errors, only
+     enable the check for GCC 12 or newer.  */
+#if __GNUC_PREREQ (12, 0)
   int ntest = 14;
   char buf1[80] __attribute__ ((aligned (16)));
   char buf2[32] __attribute__ ((aligned (16)));
@@ -464,6 +470,7 @@  test_strncat (void)
 		    }
 		}
 	  }
+#endif
 }
 
 static void