[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <447B1CEB-B525-4143-854E-9BD2069C9E16@oracle.com>
Date: Mon, 15 May 2023 19:58:37 +0000
From: Qing Zhao <qing.zhao@...cle.com>
To: Richard Biener <richard.guenther@...il.com>,
Joseph Myers <joseph@...esourcery.com>
CC: Kees Cook <keescook@...omium.org>,
Alejandro Colomar <alx.manpages@...il.com>,
GCC <gcc@....gnu.org>, Alejandro Colomar <alx@...nx.com>,
Andrew Clayton <a.clayton@...nx.com>,
Andrew Clayton <andrew@...ital-domain.net>,
"linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>
Subject: Re: [wish] Flexible array members in unions
> On May 12, 2023, at 2:16 AM, Richard Biener via Gcc <gcc@....gnu.org> wrote:
>
> On Thu, May 11, 2023 at 11:14 PM Kees Cook via Gcc <gcc@....gnu.org> wrote:
>>
>> On Thu, May 11, 2023 at 08:53:52PM +0000, Joseph Myers wrote:
>>> On Thu, 11 May 2023, Kees Cook via Gcc wrote:
>>>
>>>> On Thu, May 11, 2023 at 06:29:10PM +0200, Alejandro Colomar wrote:
>>>>> On 5/11/23 18:07, Alejandro Colomar wrote:
>>>>> [...]
>>>>>> Would you allow flexible array members in unions? Is there any
>>>>>> strong reason to disallow them?
>>>>
>>>> Yes please!! And alone in a struct, too.
>>>>
>>>> AFAICT, there is no mechanical/architectural reason to disallow them
>>>> (especially since they _can_ be constructed with some fancy tricks,
>>>> and they behave as expected.) My understanding is that it's disallowed
>>>> due to an overly strict reading of the very terse language that created
>>>> flexible arrays in C99.
>>>
>>> Standard C has no such thing as a zero-size object or type, which would
>>> lead to problems with a struct or union that only contains a flexible
>>> array member there.
>>
>> Ah-ha, okay. That root cause makes sense now.
>
> Hmm. but then the workaround
>
> struct X {
> int n;
> union u {
> char at_least_size_one;
> int iarr[];
> short sarr[];
> };
> };
>
> doesn't work either. We could make that a GNU extension without
> adverse effects?
I think that this might be a very nice extension, which addresses the standard C’s restriction on the zero-size object, and also can resolve kernel’s need. (And also other users’s similar programming need?)
And maybe it’s also possible to add such extension later to Standard C?
Similar as flexible array member in Standard C, we should limit such union as the last field of another structure. (Since basically this union can be treated
As a flexible array member)
Qing
>
> Richard.
>
>> Why are zero-sized objects missing in Standard C? Or, perhaps, the better
>> question is: what's needed to support the idea of a zero-sized object?
>>
>> --
>> Kees Cook
Powered by blists - more mailing lists