Re: [PATCH v2 6/8] dir: fix checks on common prefix directory
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 17, 2019, 00:14 UTC
- Message-ID
- <xmqqr213iz9z.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <nycvar.QRO.7.76.6.1912170101230.46@tvgsbejvaqbjf.bet>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 21 quoted lines
> If you care to look at our very own `compat/win32/dirent.h`, you will see
> this:
>
> struct dirent {
> unsigned char d_type; /* file type to prevent lstat after readdir */
> char *d_name; /* file name */
> };
>
> And looking at
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html, I
> do not see any guarantee of that `[256]` at all:
>
> The <dirent.h> header shall [...] define the structure dirent which shall
> include the following members:
>
> [XSI][Option Start]
> ino_t d_ino File serial number.
> [Option End]
> char d_name[] Filename string of entry.
>
> You will notice that not even `d_type` is guaranteed.I am reasonably sure that the code (without Elijah's patches anyway) takes the possibility of missing d_type into account already.
Doesn't the above mean d_name[] has to be an in-place array of some size (i.e. even a flex-array is OK)? It does not look to me that it allows for it to be a pointer pointing at elsewhere (possibly on heap), which may be asking for trouble.