On Thu, Feb 02, 2012 at 10:29:00PM -0700, Philip Guenther wrote:
> On Thu, 2 Feb 2012, Philip Guenther wrote:
> > I also think readdir() should set errno if it detects an invalid
> > seekdir().  EINVAL seems correct.
> 
> Here's a diff for this bit.
> 
> oks?
> 
> 
> Philip Guenther
> 
> 
> Index: gen/readdir.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/gen/readdir.c,v
> retrieving revision 1.15
> diff -u -p -r1.15 readdir.c
> --- gen/readdir.c     18 Nov 2009 07:43:22 -0000      1.15
> +++ gen/readdir.c     3 Feb 2012 05:21:58 -0000
> @@ -29,6 +29,7 @@
>   */
>  
>  #include <dirent.h>
> +#include <errno.h>
>  #include "thread_private.h"
>  
>  /*
> @@ -52,12 +53,14 @@ _readdir_unlocked(DIR *dirp, struct dire
>                               return (-1);
>               }
>               dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
> -             if ((long)dp & 03)      /* bogus pointer check */
> -                     return (-1);
> -             if (dp->d_reclen <= 0 ||
> -                 dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc)
> +             if ((long)dp & 03 ||    /* bogus pointer check */
> +                 dp->d_reclen <= 0 ||
> +                 dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) {
> +                     errno = EINVAL;
>                       return (-1);
> +             }
>               dirp->dd_loc += dp->d_reclen;
> +
>               /*
>                * When called from seekdir(), we let it decide on
>                * the end condition to avoid overshooting: the next
> 

I like this diff per se, just not enough of a POSIX lawyer to say if the
subtly different behaviour will set off alarms in Austin or wherever POSIX
hangs out these days. :-)

.... Ken

Reply via email to