public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] dlfcn: Avoid one-element flexible array in Dl_serinfo [BZ #24166]
@ 2019-06-19 8:14 Florian Weimer
0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2019-06-19 8:14 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fabf5e49ddd61312027de8e92cc1b8528c2a929d
commit fabf5e49ddd61312027de8e92cc1b8528c2a929d
Author: Florian Weimer <fweimer@redhat.com>
Date: Wed Jun 19 10:13:50 2019 +0200
dlfcn: Avoid one-element flexible array in Dl_serinfo [BZ #24166]
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.
Diff:
---
ChangeLog | 6 ++++++
dlfcn/dlfcn.h | 12 ++++++++++++
2 files changed, 18 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index ac06595..f32b734 100644
--- 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]
diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
index 896ad6f..c550371 100644
--- a/dlfcn/dlfcn.h
+++ b/dlfcn/dlfcn.h
@@ -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 */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-06-19 8:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-19 8:14 [glibc] dlfcn: Avoid one-element flexible array in Dl_serinfo [BZ #24166] Florian Weimer
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).