Re: Can struct sockaddr_un.sun_path be a flexible array member?
On Sun, Jul 17, 2022 at 03:46:52PM -0700, Nick Stoughton via austin-group-l at The Open Group wrote: > Note that a flexible array member is not the same thing as a variable > length array, and although both entered the standard in C99, previous > versions allowed the FAM to be specified as an array of length 0. > > The C standard notes that: > > In most situations, the flexible array member is ignored. In particular, > the size of the structure is as if the flexible array member were omitted > ... > and "sizeof" does just that (omits the flexible array member). > > The normative text does not seem to preclude the use of a flexible array > member but does not specify any mechanism to obtain the size if it were so. > I believe that it is a bug in the standard that it is not made clearer that > the implementation should define the size somehow. I know of no > implementation that uses a flexible array here. Please feel free to submit > a bug to austingroupbugs.net with this. Or better yet, help with amending the existing bug to propose the desired wording changes: https://www.austingroupbugs.net/view.php?id=561 Based on an earlier meeting, our current thoughts are: - Add requirement that sun_path be last member of struct sockaddr_un, and that it have a constant (although unspecified) size rather than being an open array - Add application usage to functions dealing with sockname to recommend memory > sizeof(struct sockaddr_un) preinitialized to 0 when it is desired to ensure NUL termination - Leave SUN_LEN out of the standard; we don't want variable-length sun_path -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: Can struct sockaddr_un.sun_path be a flexible array member?
Note that a flexible array member is not the same thing as a variable length array, and although both entered the standard in C99, previous versions allowed the FAM to be specified as an array of length 0. The C standard notes that: > In most situations, the flexible array member is ignored. In particular, the size of the structure is as if the flexible array member were omitted ... and "sizeof" does just that (omits the flexible array member). The normative text does not seem to preclude the use of a flexible array member but does not specify any mechanism to obtain the size if it were so. I believe that it is a bug in the standard that it is not made clearer that the implementation should define the size somehow. I know of no implementation that uses a flexible array here. Please feel free to submit a bug to austingroupbugs.net with this. On Sat, Jul 16, 2022 at 10:37 AM shwaresyst via austin-group-l at The Open Group wrote: > Short answer, no. It was erroneously specified as such in the > header because there wasn't an agreed upon symbolic constant for the size > and I believe this notation was the convention before the C standard > adopted flexible arrays. While an implementation should declare a symbolic > constant, some have just used an integer constant instead so it's left > unspecified. > > On Sat, Jul 16, 2022 at 1:13 PM, John Scott via austin-group-l at The Open > Group > wrote: > Hi list, > > I do not represent any implementations, I ask this merely as an > application developer who has asked around. > > Can .sun_path be a flexible array member? The standard says it has > unspecified size, but also normatively says > "The sockaddr_storage structure defined in shall be large > enough to accommodate a sockaddr_un structure." This doesn't clear > things up unless we have a notion of whether "size of a structure" > includes its flexible array member, and even if that is true, whether > including a flexible array member on sockaddr_storage (albeit one which > a portable application wouldn't know how to access) would satisfy this. > > The example for bind() uses sizeof() on .sun_path, suggesting the answer > to my question is "no," but examples aren't normative. > > If the standard could say whether this is permitted more clearly, that > would make me happy. > > Thanks for your attention to my inquiry, > John > >
Re: Can struct sockaddr_un.sun_path be a flexible array member?
Short answer, no. It was erroneously specified as such in the header because there wasn't an agreed upon symbolic constant for the size and I believe this notation was the convention before the C standard adopted flexible arrays. While an implementation should declare a symbolic constant, some have just used an integer constant instead so it's left unspecified. On Sat, Jul 16, 2022 at 1:13 PM, John Scott via austin-group-l at The Open Group wrote: Hi list, I do not represent any implementations, I ask this merely as an application developer who has asked around. Can .sun_path be a flexible array member? The standard says it has unspecified size, but also normatively says "The sockaddr_storage structure defined in shall be large enough to accommodate a sockaddr_un structure." This doesn't clear things up unless we have a notion of whether "size of a structure" includes its flexible array member, and even if that is true, whether including a flexible array member on sockaddr_storage (albeit one which a portable application wouldn't know how to access) would satisfy this. The example for bind() uses sizeof() on .sun_path, suggesting the answer to my question is "no," but examples aren't normative. If the standard could say whether this is permitted more clearly, that would make me happy. Thanks for your attention to my inquiry, John
Can struct sockaddr_un.sun_path be a flexible array member?
Hi list, I do not represent any implementations, I ask this merely as an application developer who has asked around. Can .sun_path be a flexible array member? The standard says it has unspecified size, but also normatively says "The sockaddr_storage structure defined in shall be large enough to accommodate a sockaddr_un structure." This doesn't clear things up unless we have a notion of whether "size of a structure" includes its flexible array member, and even if that is true, whether including a flexible array member on sockaddr_storage (albeit one which a portable application wouldn't know how to access) would satisfy this. The example for bind() uses sizeof() on .sun_path, suggesting the answer to my question is "no," but examples aren't normative. If the standard could say whether this is permitted more clearly, that would make me happy. Thanks for your attention to my inquiry, John signature.asc Description: This is a digitally signed message part