On Sun, Dec 25, 2022 at 08:07:11PM +0000, Miod Vallat wrote:
> Indeed! So the third copystr() call could be replaced with this:
> 
> Index: sys/kern/vfs_lookup.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/kern/vfs_lookup.c,v
> retrieving revision 1.87
> diff -u -p -r1.87 vfs_lookup.c
> --- sys/kern/vfs_lookup.c     14 Aug 2022 01:58:28 -0000      1.87
> +++ sys/kern/vfs_lookup.c     25 Dec 2022 20:06:27 -0000
> @@ -143,10 +143,16 @@ namei(struct nameidata *ndp)
>        */
>       if ((cnp->cn_flags & HASBUF) == 0)
>               cnp->cn_pnbuf = pool_get(&namei_pool, PR_WAITOK);
> -     if (ndp->ni_segflg == UIO_SYSSPACE)
> -             error = copystr(ndp->ni_dirp, cnp->cn_pnbuf,
> -                         MAXPATHLEN, &ndp->ni_pathlen);
> -     else
> +     if (ndp->ni_segflg == UIO_SYSSPACE) {
> +             ndp->ni_pathlen = strlcpy(cnp->cn_pnbuf, ndp->ni_dirp,
> +                 MAXPATHLEN);
> +             if (ndp->ni_pathlen >= MAXPATHLEN) {
> +                     error = ENAMETOOLONG;
> +             } else {
> +                     error = 0;
> +                     ndp->ni_pathlen++;      /* ni_pathlen includes NUL */
> +             }
> +     } else
>               error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf,
>                           MAXPATHLEN, &ndp->ni_pathlen);

Looks good to me.

Reply via email to