diff mbox series

[v2] posix: Fix test-errno build with fortify enable

Message ID 20230724193817.510337-1-adhemerval.zanella@linaro.org
State New
Headers show
Series [v2] posix: Fix test-errno build with fortify enable | expand

Commit Message

Adhemerval Zanella Netto July 24, 2023, 7:38 p.m. UTC
With gcc 11.3.1, building with -D_FORTIFY_SOURCE=2 shows:

In function ‘getgroups’,
    inlined from ‘do_test’ at test-errno.c:129:12:
../misc/sys/cdefs.h:195:6: error: argument 1 value -1 is negative
[-Werror=stringop-overflow=]
  195 |    ? __ ## f ## _alias (__VA_ARGS__)
      \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../posix/bits/unistd.h:115:10: note: in expansion of macro
‘__glibc_fortify’
  115 |   return __glibc_fortify (getgroups, __size, sizeof (__gid_t),
      |          ^~~~~~~~~~~~~~~
../posix/bits/unistd.h: In function ‘do_test’:
../posix/bits/unistd-decl.h:135:28: note: in a call to function
‘__getgroups_alias’ declared with attribute ‘access (write_only, 2, 1)’
  135 | extern int __REDIRECT_NTH (__getgroups_alias, (int __size,
      __gid_t __list[]),
      |                            ^~~~~~~~~~~~~~~~~
../misc/sys/cdefs.h:264:6: note: in definition of macro ‘__REDIRECT_NTH’
  264 |      name proto __asm__ (__ASMNAME (#alias)) __THROW

It builds fine with gcc 12 and gcc 13.

Checked on x86_64-linux-gnu.
---
 posix/test-errno.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Carlos O'Donell July 26, 2023, 1:59 a.m. UTC | #1
On 7/24/23 15:38, Adhemerval Zanella wrote:
> With gcc 11.3.1, building with -D_FORTIFY_SOURCE=2 shows:
> 
> In function ‘getgroups’,
>     inlined from ‘do_test’ at test-errno.c:129:12:
> ../misc/sys/cdefs.h:195:6: error: argument 1 value -1 is negative
> [-Werror=stringop-overflow=]
>   195 |    ? __ ## f ## _alias (__VA_ARGS__)
>       \
>       |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../posix/bits/unistd.h:115:10: note: in expansion of macro
> ‘__glibc_fortify’
>   115 |   return __glibc_fortify (getgroups, __size, sizeof (__gid_t),
>       |          ^~~~~~~~~~~~~~~
> ../posix/bits/unistd.h: In function ‘do_test’:
> ../posix/bits/unistd-decl.h:135:28: note: in a call to function
> ‘__getgroups_alias’ declared with attribute ‘access (write_only, 2, 1)’
>   135 | extern int __REDIRECT_NTH (__getgroups_alias, (int __size,
>       __gid_t __list[]),
>       |                            ^~~~~~~~~~~~~~~~~
> ../misc/sys/cdefs.h:264:6: note: in definition of macro ‘__REDIRECT_NTH’
>   264 |      name proto __asm__ (__ASMNAME (#alias)) __THROW
> 
> It builds fine with gcc 12 and gcc 13.

LGTM.

Andreas, RM OK to push?

Reviewed-by: Carlos O'Donell <carlos@redhat.com>


> Checked on x86_64-linux-gnu.
> ---
>  posix/test-errno.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/posix/test-errno.c b/posix/test-errno.c
> index 305bc42938..3685fd1555 100644
> --- a/posix/test-errno.c
> +++ b/posix/test-errno.c
> @@ -17,6 +17,13 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> +#include <sys/cdefs.h>
> +#include <libc-diag.h>
> +#if __GNUC_PREREQ (7, 0)
> +/* Triggered by getgroup fortify wrapper.  */
> +DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow");

OK. Covers the whole file.

> +#endif
> +
>  #include <errno.h>
>  #include <limits.h>
>  #include <grp.h>
> @@ -34,7 +41,6 @@
>  #include <sys/uio.h>
>  #include <unistd.h>
>  #include <netinet/in.h>
> -#include <libc-diag.h>

OK.

>  
>  /* This is not an exhaustive test: only system calls that can be
>     persuaded to fail with a consistent error code and no side effects
Andreas K. Huettel July 26, 2023, 9:18 a.m. UTC | #2
Am Mittwoch, 26. Juli 2023, 03:59:44 CEST schrieb Carlos O'Donell:
> On 7/24/23 15:38, Adhemerval Zanella wrote:
> > With gcc 11.3.1, building with -D_FORTIFY_SOURCE=2 shows:
> > 
> > In function ‘getgroups’,
> >     inlined from ‘do_test’ at test-errno.c:129:12:
> > ../misc/sys/cdefs.h:195:6: error: argument 1 value -1 is negative
> > [-Werror=stringop-overflow=]
> >   195 |    ? __ ## f ## _alias (__VA_ARGS__)
> >       \
> >       |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ../posix/bits/unistd.h:115:10: note: in expansion of macro
> > ‘__glibc_fortify’
> >   115 |   return __glibc_fortify (getgroups, __size, sizeof (__gid_t),
> >       |          ^~~~~~~~~~~~~~~
> > ../posix/bits/unistd.h: In function ‘do_test’:
> > ../posix/bits/unistd-decl.h:135:28: note: in a call to function
> > ‘__getgroups_alias’ declared with attribute ‘access (write_only, 2, 1)’
> >   135 | extern int __REDIRECT_NTH (__getgroups_alias, (int __size,
> >       __gid_t __list[]),
> >       |                            ^~~~~~~~~~~~~~~~~
> > ../misc/sys/cdefs.h:264:6: note: in definition of macro ‘__REDIRECT_NTH’
> >   264 |      name proto __asm__ (__ASMNAME (#alias)) __THROW
> > 
> > It builds fine with gcc 12 and gcc 13.
> 
> LGTM.
> 
> Andreas, RM OK to push?
> 
> Reviewed-by: Carlos O'Donell <carlos@redhat.com>

Yes please go ahead.

> 
> 
> > Checked on x86_64-linux-gnu.
> > ---
> >  posix/test-errno.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/posix/test-errno.c b/posix/test-errno.c
> > index 305bc42938..3685fd1555 100644
> > --- a/posix/test-errno.c
> > +++ b/posix/test-errno.c
> > @@ -17,6 +17,13 @@
> >     License along with the GNU C Library; if not, see
> >     <https://www.gnu.org/licenses/>.  */
> >  
> > +#include <sys/cdefs.h>
> > +#include <libc-diag.h>
> > +#if __GNUC_PREREQ (7, 0)
> > +/* Triggered by getgroup fortify wrapper.  */
> > +DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow");
> 
> OK. Covers the whole file.
> 
> > +#endif
> > +
> >  #include <errno.h>
> >  #include <limits.h>
> >  #include <grp.h>
> > @@ -34,7 +41,6 @@
> >  #include <sys/uio.h>
> >  #include <unistd.h>
> >  #include <netinet/in.h>
> > -#include <libc-diag.h>
> 
> OK.
> 
> >  
> >  /* This is not an exhaustive test: only system calls that can be
> >     persuaded to fail with a consistent error code and no side effects
> 
>
diff mbox series

Patch

diff --git a/posix/test-errno.c b/posix/test-errno.c
index 305bc42938..3685fd1555 100644
--- a/posix/test-errno.c
+++ b/posix/test-errno.c
@@ -17,6 +17,13 @@ 
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <sys/cdefs.h>
+#include <libc-diag.h>
+#if __GNUC_PREREQ (7, 0)
+/* Triggered by getgroup fortify wrapper.  */
+DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow");
+#endif
+
 #include <errno.h>
 #include <limits.h>
 #include <grp.h>
@@ -34,7 +41,6 @@ 
 #include <sys/uio.h>
 #include <unistd.h>
 #include <netinet/in.h>
-#include <libc-diag.h>
 
 /* This is not an exhaustive test: only system calls that can be
    persuaded to fail with a consistent error code and no side effects