This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] nftw: fill in stat buf for dangling links [BZ #23501]


DJ Delorie <dj@redhat.com> writes:

> diff --git a/io/ftw.c b/io/ftw.c
> index 33e1a5ecab6..1ca70a55c8d 100644
> --- a/io/ftw.c
> +++ b/io/ftw.c
> @@ -424,7 +424,31 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
>        else if (data->flags & FTW_PHYS)
>  	flag = FTW_NS;
>        else if (d_type == DT_LNK)
> -	flag = FTW_SLN;
> +	{
> +	  int err;
> +
> +	  flag = FTW_SLN;
> +
> +	  /* Old code left ST undefined; a clarification at the POSIX
> +	     level suggests it should contain information about the
> +	     link (ala lstat ()).  We do our best to fill in what data
> +	     we can.  */
> +	  if (dir->streamfd != -1)
> +	    err = FXSTATAT (_STAT_VER, dir->streamfd, name, &st,
> +			    AT_SYMLINK_NOFOLLOW);
> +	  else
> +	    err = LXSTAT (_STAT_VER, name, &st);

OK.

> +	  if (err < 0)
> +	    {
> +	      /* Stat failed.  We have three choices: don't report
> +		 this file, report with invalid data, or report with
> +		 zero'd data.  Let's prefer obvious over subtle so
> +		 zero the data here.  This should happen extremely
> +		 rarely.  */
> +	      memset (&st, 0, sizeof (st));
> +	    }

I could not find a description of this behavior in the standard.

The closest thing I found was:

     The nftw( ) function detects an error other than [EACCES] (see FTW_DNR
     and FTW_NS above), in which case nftw( ) shall return −1 and set errno
     to indicate the error.

Am I missing anything?

> diff --git a/io/tst-ftw-lnk.c b/io/tst-ftw-lnk.c
> new file mode 100644
> index 00000000000..8ee23186312
> --- /dev/null
> +++ b/io/tst-ftw-lnk.c
> @@ -0,0 +1,239 @@
> +/* Test for ftw function related to symbolic links for BZ #23501
> +   Copyright (C) 2018 Free Software Foundation, Inc.

s/2018/2019/

-- 
Tulio Magno


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]