[PATCH] io: Fix silent readdir failures in ftw/nftw (BZ 33085)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Mon Apr 20 16:40:04 GMT 2026
On 17/04/26 19:43, DJ Delorie wrote:
>
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>> diff --git a/io/ftw.c b/io/ftw.c
>> @@ -246,8 +246,16 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
>> struct dirent64 *d;
>> size_t actsize = 0;
>>
>> - while ((d = __readdir64 (st)) != NULL)
>> + while (1)
>> {
>> + errno = 0;
>> + d = __readdir64 (st);
>> + if (d == NULL)
>> + {
>> + if (errno != 0)
>> + return -1;
>
> Need to free(buf) here.
Good catch.
>
>> - frame->state = FTW_STATE_CLEANUP;
>> + {
>> + frame->state = FTW_STATE_CLEANUP;
>> + if (errno != 0)
>> + result = -1;
>
> And here.
This is is not really needed because the open_dir_stream entry will be
cleared in the FTW_STATE_CLEANUP state (the code does not return early,
but change the state to FTW_STATE_CLEANUP).
>
>> diff --git a/io/tst-ftw-bz33085.c b/io/tst-ftw-bz33085.c
>
>> +/* The test stress the readdir calls from nftw, where failures should not
>
> typo : stress -> stresses
Ack.
>
>> + handled as end of stream. The first it at 'ftw_dir'
>
> s/it/is/
>
Ack.
>> + (FTW_STATE_STREAM_LOOP) for the default entries read. The another one is
>> + at open_dir_stream where it is triggered when there is a file description
>> + exaustion and the code< must close an existing stream to make room for the
>
> extra < ("code<")
Ack.
>
> Rest looks OK.
>
More information about the Libc-alpha
mailing list