public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] string: Fix tester build with fortify enable with gcc < 12
@ 2023-08-09 12:03 bmahi496
  2023-08-09 13:40 ` Rajalakshmi Srinivasaraghavan
  2023-08-09 21:34 ` Joseph Myers
  0 siblings, 2 replies; 7+ messages in thread
From: bmahi496 @ 2023-08-09 12:03 UTC (permalink / raw)
  To: libc-alpha; +Cc: rajis, Mahesh Bodapati

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)
   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
-- 
2.31.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] string: Fix tester build with fortify enable with gcc < 12
  2023-08-09 12:03 [PATCH] string: Fix tester build with fortify enable with gcc < 12 bmahi496
@ 2023-08-09 13:40 ` Rajalakshmi Srinivasaraghavan
  2023-08-09 14:50   ` MAHESH BODAPATI
  2023-08-09 21:34 ` Joseph Myers
  1 sibling, 1 reply; 7+ messages in thread
From: Rajalakshmi Srinivasaraghavan @ 2023-08-09 13:40 UTC (permalink / raw)
  To: bmahi496, libc-alpha; +Cc: rajis


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] string: Fix tester build with fortify enable with gcc < 12
  2023-08-09 13:40 ` Rajalakshmi Srinivasaraghavan
@ 2023-08-09 14:50   ` MAHESH BODAPATI
  0 siblings, 0 replies; 7+ messages in thread
From: MAHESH BODAPATI @ 2023-08-09 14:50 UTC (permalink / raw)
  To: Rajalakshmi Srinivasaraghavan, libc-alpha; +Cc: rajis


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] string: Fix tester build with fortify enable with gcc < 12
  2023-08-09 12:03 [PATCH] string: Fix tester build with fortify enable with gcc < 12 bmahi496
  2023-08-09 13:40 ` Rajalakshmi Srinivasaraghavan
@ 2023-08-09 21:34 ` Joseph Myers
  2023-08-10  7:09   ` MAHESH BODAPATI
  1 sibling, 1 reply; 7+ messages in thread
From: Joseph Myers @ 2023-08-09 21:34 UTC (permalink / raw)
  To: Mahesh Bodapati; +Cc: libc-alpha, rajis

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?

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] string: Fix tester build with fortify enable with gcc < 12
  2023-08-09 21:34 ` Joseph Myers
@ 2023-08-10  7:09   ` MAHESH BODAPATI
  2023-08-10 14:33     ` Joseph Myers
  0 siblings, 1 reply; 7+ messages in thread
From: MAHESH BODAPATI @ 2023-08-10  7:09 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha, rajis

[-- Attachment #1: Type: text/plain, Size: 1444 bytes --]


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));//
//      | ~~~~~~~~~~~~~~~~~~~~~~~~~/


>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] string: Fix tester build with fortify enable with gcc < 12
  2023-08-10  7:09   ` MAHESH BODAPATI
@ 2023-08-10 14:33     ` Joseph Myers
  2023-08-11 13:34       ` MAHESH BODAPATI
  0 siblings, 1 reply; 7+ messages in thread
From: Joseph Myers @ 2023-08-10 14:33 UTC (permalink / raw)
  To: MAHESH BODAPATI; +Cc: libc-alpha, rajis

[-- Attachment #1: Type: text/plain, Size: 1622 bytes --]

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)?

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] string: Fix tester build with fortify enable with gcc < 12
  2023-08-10 14:33     ` Joseph Myers
@ 2023-08-11 13:34       ` MAHESH BODAPATI
  0 siblings, 0 replies; 7+ messages in thread
From: MAHESH BODAPATI @ 2023-08-11 13:34 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha, rajis


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.


>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-11 13:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-09 12:03 [PATCH] string: Fix tester build with fortify enable with gcc < 12 bmahi496
2023-08-09 13:40 ` Rajalakshmi Srinivasaraghavan
2023-08-09 14:50   ` MAHESH BODAPATI
2023-08-09 21:34 ` Joseph Myers
2023-08-10  7:09   ` MAHESH BODAPATI
2023-08-10 14:33     ` Joseph Myers
2023-08-11 13:34       ` MAHESH BODAPATI

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).