bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug 984910] rm fails to detect errors in readdir(3)


From: Pádraig Brady
Subject: Re: [Bug 984910] rm fails to detect errors in readdir(3)
Date: Wed, 22 Jun 2016 13:48:38 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 22/06/16 13:18, Bernhard Voelker wrote:
> On 06/22/2016 01:00 PM, Pádraig Brady wrote:
>> How about the attached instead?
> 
> That's a sensible solution.
> 
>> diff --git a/lib/fts.c b/lib/fts.c
>> index bcdcff9..d022633 100644
>> --- a/lib/fts.c
>> +++ b/lib/fts.c
>> @@ -1461,9 +1461,15 @@ fts_build (register FTS *sp, int type)
>>          while (cur->fts_dirp) {
>>                  bool is_dir;
>>                  size_t d_namelen;
>> +                __set_errno (0);
>>                  struct dirent *dp = readdir(cur->fts_dirp);
>> -                if (dp == NULL)
>> +                if (dp == NULL) {
>> +                        if (errno) {
>> +                                cur->fts_errno = errno;
>> +                                cur->fts_info = items ? FTS_ERR : FTS_DNR;
> 
> s/items/nitems/
> 
>> +                        }
>>                          break;
>> +                }
>>                  if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
>>                          continue;
>>  
>> @@ -1622,7 +1628,7 @@ mem1:                           saved_errno = errno;
>>  
>>          /* If didn't find anything, return NULL. */
>>          if (!nitems) {
>> -                if (type == BREAD)
>> +                if (type == BREAD && cur->fts_info != FTS_DNR)
>>                          cur->fts_info = FTS_DP;
>>                  fts_lfree(head);
>>                  return (NULL);
> 
> Other than the above typo, this looks good to me, thanks!
> Unfortunately, it seems we don't have test for fts.c, do we?

Not that I know of.
For effective testing of this you'd have to use something like cmocka,
or more generically something like CharybdeFS

cheers,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]