dlfcn: Avoid one-element flexible array in Dl_serinfo
Commit Message
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.
@@ -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 */