]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
dlfcn: Avoid one-element flexible array in Dl_serinfo [BZ #24166]
authorFlorian Weimer <fweimer@redhat.com>
Wed, 19 Jun 2019 08:13:50 +0000 (10:13 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 19 Jun 2019 08:13:50 +0000 (10:13 +0200)
The dls_serpath path field, as an array of length 1, introduces
unexpected array subscript checks with some compilers.

GCC versions before 3.0 treat the nested anonymous union as a
declaration of an unnamed type, and not as a member declaration,
so this construct cannot be used for these compilers.

ChangeLog
dlfcn/dlfcn.h

index ac06595fb41ec308bf71926bf1bea535c8eac04b..f32b734166db88304ef7163be27e3a0b7946cf9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-06-19  Florian Weimer  <fweimer@redhat.com>
+
+       [BZ #24166]
+       * dlfcn/dlfcn.h (Dl_serinfo): Do not use array of length 1 for
+       dls_serpath field.
+
 2019-06-18  Florian Weimer  <fweimer@redhat.com>
 
        [BZ #24323]
index 896ad6fc9bfd93b4e9b43ab18dd41db8330c97df..c5503719994a365c7b83b0cf886bf050a9136635 100644 (file)
@@ -180,7 +180,19 @@ typedef struct
 {
   size_t dls_size;             /* Size in bytes of the whole buffer.  */
   unsigned int dls_cnt;                /* Number of elements in `dls_serpath'.  */
+# if __GNUC_PREREQ (3, 0)
+  /* The zero-length array avoids an unwanted array subscript check by
+     the compiler, while the surrounding anonymous union preserves the
+     historic size of the type.  At the time of writing, GNU C does
+     not support structs with flexible array members in unions.  */
+  __extension__ union
+  {
+    Dl_serpath dls_serpath[0]; /* Actually longer, dls_cnt elements.  */
+    Dl_serpath __dls_serpath_pad[1];
+  };
+# else
   Dl_serpath dls_serpath[1];   /* Actually longer, dls_cnt elements.  */
+# endif
 } Dl_serinfo;
 #endif /* __USE_GNU */