This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [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: Mon, 03 Jun 2019 09:59:10 +0200
- Subject: Re: [PATCH] dlfcn: Avoid one-element flexible array in Dl_serinfo
- References: <87k1ehzf7o.fsf@oldenburg2.str.redhat.com> <437469fe-7622-9021-0b0c-5e4a1cdb8482@cs.ucla.edu> <8736l4utui.fsf@oldenburg2.str.redhat.com> <d8732d23-4ebc-1530-bc37-1945778d05fe@cs.ucla.edu> <87imtvhg7w.fsf@oldenburg2.str.redhat.com>
* Florian Weimer:
> diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
> index 896ad6fc9b..7107b3ea9a 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'. */
> +# ifdef __GNUC__
> + /* 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 /* !__GNUC__ */
> Dl_serpath dls_serpath[1]; /* Actually longer, dls_cnt elements. */
> +# endif /* !__GNUC__ */
> } Dl_serinfo;
> #endif /* __USE_GNU */
>
It turns out that GCC 2.7.2.3 treats this anonymous union as a type
declaration and ignores it. I will try to come up with the appropriate
__GNUC_PREREQ conditional.
(Don't get the wrong idea; we do not test regularly against older GCC
versions.)
Thanks,
Florian