bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* test-getgroups.c:stringop-overflow warning on newer GCC
@ 2020-12-08 22:57 Bernhard Voelker
  2021-01-01 12:56 ` Bruno Haible
  0 siblings, 1 reply; 8+ messages in thread
From: Bernhard Voelker @ 2020-12-08 22:57 UTC (permalink / raw)
  To: bug-gnulib

Newer GCC complains about this test:

  $ make test-getgroups.o V=1
  depbase=`echo test-getgroups.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
  gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I..  -DIN_FINDUTILS_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gl/lib -I./.. \
    /gl/lib   -g -O2 -MT test-getgroups.o -MD -MP -MF $depbase.Tpo -c -o test-getgroups.o test-getgroups.c &&\
  mv -f $depbase.Tpo $depbase.Po
  In file included from test-getgroups.c:31:
  test-getgroups.c: In function 'main':
  test-getgroups.c:65:11: warning: argument 1 value -1 is negative [-Wstringop-overflow=]
     65 |   ASSERT (getgroups (-1, NULL) == -1);
        |           ^~~~~~~~~~~~~~~~~~~~
  macros.h:57:13: note: in definition of macro 'ASSERT'
     57 |       if (!(expr))                                                           \
        |             ^~~~
  In file included from ../gl/lib/unistd.h:40,
                   from test-getgroups.c:21:
  /usr/include/unistd.h:701:12: note: in a call to function 'getgroups' declared with attribute 'write_only (2, 1)'
    701 | extern int getgroups (int __size, __gid_t __list[]) __THROW __wur
        |            ^~~~~~~~~

This is the whole declaration from the system's unistd.h:

  $ sed -n 698,702p /usr/include/unistd.h
  /* If SIZE is zero, return the number of supplementary groups
     the calling process is in.  Otherwise, fill in the group IDs
     of its supplementary groups in LIST and return the number written.  */
  extern int getgroups (int __size, __gid_t __list[]) __THROW __wur
      __attr_access ((__write_only__, 2, 1));

I could reproduce on openSUSE:Tumbleweed and Fedora 33,
both having GCC-10.2.1:

  $ gcc --version | sed 1q
  gcc (SUSE Linux) 10.2.1 20201117 [revision 98ba03ffe0b9f37b4916ce6238fad754e00d720b]

  $ gcc --version | sed 1q
  gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)

Well, the test is explicitly testing the behavior when passing a negative number.
Maybe we should add this to the test?

  # pragma GCC diagnostic ignored "-Wstringop-overflow"

Thanks & have a nice day,
Berny


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

* Re: test-getgroups.c:stringop-overflow warning on newer GCC
  2020-12-08 22:57 test-getgroups.c:stringop-overflow warning on newer GCC Bernhard Voelker
@ 2021-01-01 12:56 ` Bruno Haible
  2021-01-02  1:43   ` Bernhard Voelker
  0 siblings, 1 reply; 8+ messages in thread
From: Bruno Haible @ 2021-01-01 12:56 UTC (permalink / raw)
  To: bug-gnulib, Bernhard Voelker

Hi Berny,

Bernhard Voelker wrote in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00090.html>:
> Newer GCC complains about this test:
> 
>   $ make test-getgroups.o V=1
>   depbase=`echo test-getgroups.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
>   gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I..  -DIN_FINDUTILS_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gl/lib -I./.. \
>     /gl/lib   -g -O2 -MT test-getgroups.o -MD -MP -MF $depbase.Tpo -c -o test-getgroups.o test-getgroups.c &&\
>   mv -f $depbase.Tpo $depbase.Po
>   In file included from test-getgroups.c:31:
>   test-getgroups.c: In function 'main':
>   test-getgroups.c:65:11: warning: argument 1 value -1 is negative [-Wstringop-overflow=]
>      65 |   ASSERT (getgroups (-1, NULL) == -1);
>         |           ^~~~~~~~~~~~~~~~~~~~

I can't reproduce this with a testdir created through
  ./gnulib-tool --create-testdir --dir=... --single-configure getgroups
and GCC 10.2.0, even with '-Wall' (whereas the GCC invocation that you show does
not invoke any warning options!):

$ gcc -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib   -g -O2 -c test-getgroups.c -Wall
(no diagnostics)

Also, it's strange that this warning reports to come from -Wstringop-overflow
— whereas 'getgroups' is not a string operation.

So, to me it looks like a bug in the particular GCC version that you are using.

Under regular circumstances, I would consider adding a #pragma GCC diagnostic,
as you suggest, but not under these circumstances.

Bruno



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

* Re: test-getgroups.c:stringop-overflow warning on newer GCC
  2021-01-01 12:56 ` Bruno Haible
@ 2021-01-02  1:43   ` Bernhard Voelker
  2021-01-02  1:59     ` Bruno Haible
  0 siblings, 1 reply; 8+ messages in thread
From: Bernhard Voelker @ 2021-01-02  1:43 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

Hi Bruno,

On 1/1/21 1:56 PM, Bruno Haible wrote:
> Hi Berny,
> 
> Bernhard Voelker wrote in
> <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00090.html>:
>> Newer GCC complains about this test:
>>
>>   $ make test-getgroups.o V=1
>>   depbase=`echo test-getgroups.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
>>   gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I..  -DIN_FINDUTILS_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gl/lib -I./.. \
>>     /gl/lib   -g -O2 -MT test-getgroups.o -MD -MP -MF $depbase.Tpo -c -o test-getgroups.o test-getgroups.c &&\
>>   mv -f $depbase.Tpo $depbase.Po
>>   In file included from test-getgroups.c:31:
>>   test-getgroups.c: In function 'main':
>>   test-getgroups.c:65:11: warning: argument 1 value -1 is negative [-Wstringop-overflow=]
>>      65 |   ASSERT (getgroups (-1, NULL) == -1);
>>         |           ^~~~~~~~~~~~~~~~~~~~
> 
> I can't reproduce this with a testdir created through
>   ./gnulib-tool --create-testdir --dir=... --single-configure getgroups
> and GCC 10.2.0, even with '-Wall' (whereas the GCC invocation that you show does
> not invoke any warning options!):
yes, this shows up without -Wall here.

> $ gcc -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib   -g -O2 -c test-getgroups.c -Wall
> (no diagnostics)

I reproduced again without -Wall both on my openSUSE Tumbleweed system with
  gcc (SUSE Linux) 10.2.1 20201202 [revision e563687cf9d3d1278f45aaebd03e0f66531076c9]
and on Fedora (in a docker container) with
  gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)

So it may be an issue with the 10.2.1 version

> Also, it's strange that this warning reports to come from -Wstringop-overflow
> — whereas 'getgroups' is not a string operation>
> So, to me it looks like a bug in the particular GCC version that you are using.
> 
> Under regular circumstances, I would consider adding a #pragma GCC diagnostic,
> as you suggest, but not under these circumstances.

I'm not sure how to proceed from here.

Have a nice day,
Berny


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

* Re: test-getgroups.c:stringop-overflow warning on newer GCC
  2021-01-02  1:43   ` Bernhard Voelker
@ 2021-01-02  1:59     ` Bruno Haible
  2021-01-02  2:30       ` Bernhard Voelker
  0 siblings, 1 reply; 8+ messages in thread
From: Bruno Haible @ 2021-01-02  1:59 UTC (permalink / raw)
  To: Bernhard Voelker; +Cc: bug-gnulib

Hi Berny,

> So it may be an issue with the 10.2.1 version
> ...
> I'm not sure how to proceed from here.

The most interesting piece of information is the rationale of this
warning (i.e. more precisely why the warning is enabled by default).
Maybe it can be found in the set of patches of this GCC version and/or
its Changelog?

Bruno



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

* Re: test-getgroups.c:stringop-overflow warning on newer GCC
  2021-01-02  1:59     ` Bruno Haible
@ 2021-01-02  2:30       ` Bernhard Voelker
  2021-01-02  3:33         ` Paul Eggert
  0 siblings, 1 reply; 8+ messages in thread
From: Bernhard Voelker @ 2021-01-02  2:30 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib

Hi Bruno,

On 1/2/21 2:59 AM, Bruno Haible wrote:
> Hi Berny,
> 
>> So it may be an issue with the 10.2.1 version
>> ...
>> I'm not sure how to proceed from here.
> 
> The most interesting piece of information is the rationale of this
> warning (i.e. more precisely why the warning is enabled by default).
> Maybe it can be found in the set of patches of this GCC version and/or
> its Changelog?
> 
> Bruno
> 

I can't find a trace about it.  The GCC on my Tumbleweed is based on
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e563687cf9d3d1278f45aaebd
with only a handful of unrelated patches.

As I see the same on Fedora, the issue seems to be upstream, doesn't it?
Cloning 'gcc.git' with my slow connection takes a while.  But I'm not sure
whether I'll be able to find something in the GCC sources after the tag
'releases/gcc-10.2.0' (your version).

Have a nice day,
Berny


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

* Re: test-getgroups.c:stringop-overflow warning on newer GCC
  2021-01-02  2:30       ` Bernhard Voelker
@ 2021-01-02  3:33         ` Paul Eggert
  2021-01-02 12:51           ` Bruno Haible
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Eggert @ 2021-01-02  3:33 UTC (permalink / raw)
  To: Bernhard Voelker; +Cc: Bruno Haible, bug-gnulib

On 1/1/21 6:30 PM, Bernhard Voelker wrote:
> As I see the same on Fedora, the issue seems to be upstream, doesn't it?

I see the problem on Fedora 33 as well. It doesn't appear to be a GCC 
bug. unistd.h's declaration expands to this:

extern int getgroups (int __size, __gid_t __list[]) __attribute__ 
((__nothrow__, __leaf__)) __attribute__ ((__access__ (__write_only__, 2, 
1)));

and the "__write_only__, 2, 1" means that getgroup's 1st argument 
specifies the number of items in the 2nd-argument array, which means if 
the 1st argument is -1 the call is invalid. This checking is enabled by 
-Wstringop-overflow=2 which is the GCC default in 10.2.1.

I am using gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9).


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

* Re: test-getgroups.c:stringop-overflow warning on newer GCC
  2021-01-02  3:33         ` Paul Eggert
@ 2021-01-02 12:51           ` Bruno Haible
  2021-01-02 19:21             ` Bernhard Voelker
  0 siblings, 1 reply; 8+ messages in thread
From: Bruno Haible @ 2021-01-02 12:51 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Bernhard Voelker, bug-gnulib

Paul Eggert wrote:
> I see the problem on Fedora 33 as well. It doesn't appear to be a GCC 
> bug. unistd.h's declaration expands to this:
> 
> extern int getgroups (int __size, __gid_t __list[]) __attribute__ 
> ((__nothrow__, __leaf__)) __attribute__ ((__access__ (__write_only__, 2, 
> 1)));
> 
> and the "__write_only__, 2, 1" means that getgroup's 1st argument 
> specifies the number of items in the 2nd-argument array, which means if 
> the 1st argument is -1 the call is invalid. This checking is enabled by 
> -Wstringop-overflow=2 which is the GCC default in 10.2.1.

I see. Thanks for explaining. Now that makes sense.


2021-01-02  Bruno Haible  <bruno@clisp.org>

	getgroups test: Avoid warning with glibc >= 2.32 and gcc >= 10.
	Reported by Bernhard Voelker <mail@bernhard-voelker.de> in
	<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00090.html>.
	* tests/test-getgroups.c: Silence gcc warnings of type
	-Wstringop-overflow.

diff --git a/tests/test-getgroups.c b/tests/test-getgroups.c
index 14e0e8f..dcea033 100644
--- a/tests/test-getgroups.c
+++ b/tests/test-getgroups.c
@@ -30,6 +30,15 @@ SIGNATURE_CHECK (getgroups, int, (int, gid_t[]));
 
 #include "macros.h"
 
+/* Tell GCC not to warn about the specific edge cases tested here.
+   GCC >= 10 with glibc >= 2.32 would otherwise trigger warnings, even without
+   any -W options, because getgroups() is declared with
+     __attribute__ ((__access__ (__write_only__, 2, 1)))
+ */
+#if __GNUC__ >= 7
+# pragma GCC diagnostic ignored "-Wstringop-overflow"
+#endif
+
 int
 main (int argc, char **argv _GL_UNUSED)
 {



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

* Re: test-getgroups.c:stringop-overflow warning on newer GCC
  2021-01-02 12:51           ` Bruno Haible
@ 2021-01-02 19:21             ` Bernhard Voelker
  0 siblings, 0 replies; 8+ messages in thread
From: Bernhard Voelker @ 2021-01-02 19:21 UTC (permalink / raw)
  To: Bruno Haible, Paul Eggert; +Cc: bug-gnulib

On 1/2/21 1:51 PM, Bruno Haible wrote:
> 2021-01-02  Bruno Haible  <bruno@clisp.org>
> 
> 	getgroups test: Avoid warning with glibc >= 2.32 and gcc >= 10.

Thanks, works.

Have a nice day,
Berny


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

end of thread, other threads:[~2021-01-02 19:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 22:57 test-getgroups.c:stringop-overflow warning on newer GCC Bernhard Voelker
2021-01-01 12:56 ` Bruno Haible
2021-01-02  1:43   ` Bernhard Voelker
2021-01-02  1:59     ` Bruno Haible
2021-01-02  2:30       ` Bernhard Voelker
2021-01-02  3:33         ` Paul Eggert
2021-01-02 12:51           ` Bruno Haible
2021-01-02 19:21             ` Bernhard Voelker

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