public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug build/26686] New: -Warray-parameter instances building with GCC 11
@ 2020-10-01  0:19 msebor at gmail dot com
  2020-10-05 15:35 ` [Bug build/26686] " msebor at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gmail dot com @ 2020-10-01  0:19 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26686

            Bug ID: 26686
           Summary: -Warray-parameter instances building with GCC 11
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: build
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at gmail dot com
                CC: carlos at redhat dot com
  Target Milestone: ---

GCC 11 has recently gained a couple of new options designed to help improve the
consistency of the forms of array and VLA paremeters between redeclarations of
the same function, detect likely incompatible forms of VLA parameters, and help
detect out of bounds accesses to such arguments.  The options are
-Warray-parameter and -Wvla-parameter.

A Glibc build with the latest GCC shows the following instances of the former. 
All appear to be by design and can be avoided simply by consistently declaring
the functions with the same array form (I recommend using the constant bound
since GCC uses it to detect out-of-bounds accesses in calls to the functions as
well as by the function bodies).

netname.c:32:20: warning: argument 1 of type ‘char[256]’ with mismatched bound
[-Warray-parameter=]
   32 | user2netname (char netname[MAXNETNAMELEN + 1], const uid_t uid,
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/rpc/auth.h:2,
                 from ../sunrpc/rpc/rpc.h:45,
                 from ../include/rpc/rpc.h:2,
                 from netname.c:22:
../sunrpc/rpc/auth.h:184:26: note: previously declared as ‘char *’
  184 | extern int user2netname (char *, const uid_t, const char *) __THROW;
      |                          ^~~~~~
netname.c:61:20: warning: argument 1 of type ‘char[256]’ with mismatched bound
[-Warray-parameter=]
   61 | host2netname (char netname[MAXNETNAMELEN + 1], const char *host,
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/rpc/auth.h:2,
                 from ../sunrpc/rpc/rpc.h:45,
                 from ../include/rpc/rpc.h:2,
                 from netname.c:22:
../sunrpc/rpc/auth.h:183:26: note: previously declared as ‘char *’
  183 | extern int host2netname (char *, const char *, const char *) __THROW;
      |                          ^~~~~~
netname.c:126:18: warning: argument 1 of type ‘char[256]’ with mismatched bound
[-Warray-parameter=]
  126 | getnetname (char name[MAXNETNAMELEN + 1])
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/rpc/auth.h:2,
                 from ../sunrpc/rpc/rpc.h:45,
                 from ../include/rpc/rpc.h:2,
                 from netname.c:22:
../sunrpc/rpc/auth.h:182:24: note: previously declared as ‘char *’
  182 | extern int getnetname (char *) __THROW;
      |                        ^~~~~~
netname.c:145:26: warning: argument 1 of type ‘const char[256]’ with mismatched
bound [-Warray-parameter=]
  145 | netname2user (const char netname[MAXNETNAMELEN + 1], uid_t * uidp,
gid_t * gidp,
      |               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/rpc/auth.h:2,
                 from ../sunrpc/rpc/rpc.h:45,
                 from ../include/rpc/rpc.h:2,
                 from netname.c:22:
../sunrpc/rpc/auth.h:185:26: note: previously declared as ‘const char *’
  185 | extern int netname2user (const char *, uid_t *, gid_t *, int *, gid_t
*)
      |                          ^~~~~~~~~~~~
netname.c:192:26: warning: argument 1 of type ‘const char[256]’ with mismatched
bound [-Warray-parameter=]
  192 | netname2host (const char netname[MAXNETNAMELEN + 1], char *hostname,
      |               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/rpc/auth.h:2,
                 from ../sunrpc/rpc/rpc.h:45,
                 from ../include/rpc/rpc.h:2,
                 from netname.c:22:
../sunrpc/rpc/auth.h:187:26: note: previously declared as ‘const char *’
  187 | extern int netname2host (const char *, char *, const int) __THROW;
      |                          ^~~~~~~~~~~~
fetch-value.c:143:27: warning: argument 2 of type ‘uint32_t[2]’ {aka ‘unsigned
int[2]’} with mismatched bound [-Warray-parameter=]
  143 |                  uint32_t desc[2], int descriptor_name, psaddr_t idx,
      |                  ~~~~~~~~~^~~~~~~
In file included from fetch-value.c:19:
thread_dbP.h:238:44: note: previously declared as ‘uint32_t[3]’ {aka ‘unsigned
int[3]’}
  238 |                                  db_desc_t field, int descriptor_name,
      |                                  ~~~~~~~~~~^~~~~
fetch-value.c:243:33: warning: argument 2 of type ‘uint32_t[2]’ {aka ‘unsigned
int[2]’} with mismatched bound [-Warray-parameter=]
  243 |                        uint32_t desc[2], int descriptor_name, psaddr_t
idx,
      |                        ~~~~~~~~~^~~~~~~
In file included from fetch-value.c:19:
thread_dbP.h:242:50: note: previously declared as ‘uint32_t[3]’ {aka ‘unsigned
int[3]’}
  242 |                                        db_desc_t field, int
descriptor_name,
      |                                        ~~~~~~~~~~^~~~~

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug build/26686] -Warray-parameter instances building with GCC 11
  2020-10-01  0:19 [Bug build/26686] New: -Warray-parameter instances building with GCC 11 msebor at gmail dot com
@ 2020-10-05 15:35 ` msebor at gmail dot com
  2020-10-05 16:49 ` joseph at codesourcery dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gmail dot com @ 2020-10-05 15:35 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26686

--- Comment #1 from Martin Sebor <msebor at gmail dot com> ---
The patch below avoids the warnings RPC by changing the declarations to match
the definitions, following the Sun/Oracle RPC manual which documents the APIs
as expecting arrays with at least MAXNETNAMELEN + 1 elements:

  https://docs.oracle.com/cd/E36784_01/html/E36875/getnetname-3nsl.html

diff --git a/sunrpc/rpc/auth.h b/sunrpc/rpc/auth.h
index e01b077214..6302e6e83b 100644
--- a/sunrpc/rpc/auth.h
+++ b/sunrpc/rpc/auth.h
@@ -179,12 +179,15 @@ extern AUTH *authdes_pk_create (const char *, netobj *,
u_int,
  *  Netname manipulating functions
  *
  */
-extern int getnetname (char *) __THROW;
-extern int host2netname (char *, const char *, const char *) __THROW;
-extern int user2netname (char *, const uid_t, const char *) __THROW;
-extern int netname2user (const char *, uid_t *, gid_t *, int *, gid_t *)
-     __THROW;
-extern int netname2host (const char *, char *, const int) __THROW;
+extern int getnetname (char [MAXNETNAMELEN + 1]) __THROW;
+extern int host2netname (char [MAXNETNAMELEN + 1], const char *,
+                        const char *) __THROW;
+extern int user2netname (char [MAXNETNAMELEN + 1], const uid_t,
+                        const char *) __THROW;
+extern int netname2user (const char [MAXNETNAMELEN + 1], uid_t *, gid_t *,
+                        int *, gid_t *) __THROW;
+extern int netname2host (const char[MAXNETNAMELEN + 1], char *,
+                        const int);

 /*
  *

The Oracle manual also describes the last argument to netname2user as an array
of NGRPS elements:

  int netname2user (const char *name, uid_t *uidp, gid_t *gidp, int *gidlenp,
                    gid_t *gidlist [NGRPS]);

so adjust those declarations in Glibc to match would make it possible to detect
calls with smaller arrays.  (The NGRPS macro is is defined in auth_unix.h.)

The following patch adjusts the signatures of the functions in
nptl_db/fetch-value.c to match the declarations.  db_desc_t is a typedef
defined near the top of thread_dbP.h as an array of three elements like so:

  typedef uint32_t db_desc_t[3];

but the definitions assume the array has just two elements.  Since the
functions only access the first element of the array (via the DB_DESC_SIZE()
macro), an alternate change is to have both their declarations and definitions
take a uint32_t[1] instead.

diff --git a/nptl_db/fetch-value.c b/nptl_db/fetch-value.c
index 128d736adb..8f1ff74fd0 100644
--- a/nptl_db/fetch-value.c
+++ b/nptl_db/fetch-value.c
@@ -140,7 +140,7 @@ _td_fetch_value (td_thragent_t *ta,

 td_err_e
 _td_store_value (td_thragent_t *ta,
-                uint32_t desc[2], int descriptor_name, psaddr_t idx,
+                db_desc_t desc, int descriptor_name, psaddr_t idx,
                 psaddr_t address, psaddr_t widened_value)
 {
   ps_err_e err;
@@ -240,7 +240,7 @@ _td_fetch_value_local (td_thragent_t *ta,

 td_err_e
 _td_store_value_local (td_thragent_t *ta,
-                      uint32_t desc[2], int descriptor_name, psaddr_t idx,
+                      db_desc_t desc, int descriptor_name, psaddr_t idx,
                       void *address, psaddr_t widened_value)
 {
   td_err_e terr = _td_locate_field (ta, desc, descriptor_name, idx, &address);

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug build/26686] -Warray-parameter instances building with GCC 11
  2020-10-01  0:19 [Bug build/26686] New: -Warray-parameter instances building with GCC 11 msebor at gmail dot com
  2020-10-05 15:35 ` [Bug build/26686] " msebor at gmail dot com
@ 2020-10-05 16:49 ` joseph at codesourcery dot com
  2020-10-05 21:46 ` msebor at gmail dot com
  2020-10-29 17:45 ` jsm28 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: joseph at codesourcery dot com @ 2020-10-05 16:49 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26686

--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
Please send these patches to libc-alpha.  (It's useful to get these fixes 
into glibc incrementally, even when there are other errors still present 
affecting the build with GCC 11.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug build/26686] -Warray-parameter instances building with GCC 11
  2020-10-01  0:19 [Bug build/26686] New: -Warray-parameter instances building with GCC 11 msebor at gmail dot com
  2020-10-05 15:35 ` [Bug build/26686] " msebor at gmail dot com
  2020-10-05 16:49 ` joseph at codesourcery dot com
@ 2020-10-05 21:46 ` msebor at gmail dot com
  2020-10-29 17:45 ` jsm28 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gmail dot com @ 2020-10-05 21:46 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26686

--- Comment #3 from Martin Sebor <msebor at gmail dot com> ---
I posted the RPC change here:
  https://sourceware.org/pipermail/libc-alpha/2020-October/118348.html
and the thread db change separately here:
  https://sourceware.org/pipermail/libc-alpha/2020-October/118354.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug build/26686] -Warray-parameter instances building with GCC 11
  2020-10-01  0:19 [Bug build/26686] New: -Warray-parameter instances building with GCC 11 msebor at gmail dot com
                   ` (2 preceding siblings ...)
  2020-10-05 21:46 ` msebor at gmail dot com
@ 2020-10-29 17:45 ` jsm28 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2020-10-29 17:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26686

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |2.33
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Joseph Myers <jsm28 at gcc dot gnu.org> ---
This was fixed for 2.33 (commits 3eff7504cab0c406dbd27a1b07a413dafc39634d and
c5db00dc30e0513dc17ad8aefe54c807f55ec967).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2020-10-29 17:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01  0:19 [Bug build/26686] New: -Warray-parameter instances building with GCC 11 msebor at gmail dot com
2020-10-05 15:35 ` [Bug build/26686] " msebor at gmail dot com
2020-10-05 16:49 ` joseph at codesourcery dot com
2020-10-05 21:46 ` msebor at gmail dot com
2020-10-29 17:45 ` jsm28 at gcc dot gnu.org

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