This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] dlfcn: Avoid one-element flexible array in Dl_serinfo
- From: Florian Weimer <fweimer at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 23 May 2019 11:34:51 +0200
- Subject: [PATCH] dlfcn: Avoid one-element flexible array in Dl_serinfo
The dls_serpath path field, as an array of length 1, introduces
unexpected array subscript checks with some compilers. Using a
zero-length array (a GNU extension) avoids that. The anonymous union
preserves the original size of the type.
2019-05-23 Florian Weimer <fweimer@redhat.com>
[BZ #24166]
* dlfcn/dlfcn.h (Dl_serinfo): Do not use array of length 1 for
dls_serpath field.
diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
index 896ad6fc9b..2ffb13d424 100644
--- a/dlfcn/dlfcn.h
+++ b/dlfcn/dlfcn.h
@@ -180,7 +180,17 @@ typedef struct
{
size_t dls_size; /* Size in bytes of the whole buffer. */
unsigned int dls_cnt; /* Number of elements in `dls_serpath'. */
+# ifdef __GNUC__
+ /* This avoids an unwanted array subscript check by the compiler,
+ while preserving the size of the type. */
+ __extension__ union
+ {
+ Dl_serpath dls_serpath[0]; /* Actually longer, dls_cnt elements. */
+ Dl_serpath __dls_serpath_pad[1];
+ };
+# else /* !__GNUC__ */
Dl_serpath dls_serpath[1]; /* Actually longer, dls_cnt elements. */
+# endif /* !__GNUC__ */
} Dl_serinfo;
#endif /* __USE_GNU */