Re: [PATCH v2 6/8] dir: fix checks on common prefix directory
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Dec 17, 2019, 19:32 UTC
- Message-ID
- <nycvar.QRO.7.76.6.1912172031490.46@tvgsbejvaqbjf.bet>
- In-Reply-To
- <xmqqk16uj1qa.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Tue, 17 Dec 2019, Junio C Hamano wrote:
Show 53 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> >> > [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.
> >
> > You are right, of course.
> >
> > ...
> >
> > Is this compliant with POSIX? I guess not. Does it work? Yes, it does.
>
> I actually would not throw it into "it works" category. The obvious
> implication is that a program like this:
>
> static struct dirent *fabricate(const char *name)
> {
> /* over-allocate as we do not know how long the d_name[] is */
> struct dirent *ent = calloc(1, sizeof(*ent) + strlen(name) + 1);
> strcpy(ent->d_name, name);
> return ent;
> }
>
> static void show_name(const struct dirent *ent)
> {
> printf("%s\n", ent->d_name);
> }
>
> int main(int ac, char **av)
> {
> struct dirent *mine = fabricate("mine");
> show_name(mine);
> free(mine);
> return 0;
> }
>
> would be broken if you do not have d_name as an array.
>
> I would not be surprised if the segfaults you saw with Elijah's
> series all were caused by your d_name not being an array, and if
> that is the case, I'd rather see it fixed on your end than fixes
> withdrawn.I agree with this reasoning.
Ciao, Dscho