[PATCH] io: Fix silent readdir failures in ftw/nftw (BZ 33085)

DJ Delorie dj@redhat.com
Fri Apr 17 22:43:00 GMT 2026


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.

> -	    frame->state = FTW_STATE_CLEANUP;
> +	    {
> +	      frame->state = FTW_STATE_CLEANUP;
> +	      if (errno != 0)
> +		result = -1;

And here.

> 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

> +   handled as end of stream.  The first it at 'ftw_dir'

s/it/is/

> +   (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<")

Rest looks OK.



More information about the Libc-alpha mailing list