On 3 February 2012 03:29, Philip Guenther <guent...@gmail.com> 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

ok by me, the other case is assured by the above getdirentries() call.

Reply via email to