tech-kern archive

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

Re: fixing compat_12 getdents



On Mon, Dec 10, 2012 at 08:09:19AM -0800, Chuck Silvers wrote:
> +     odp = (struct dirent12 *)(void *)buf;
> +     ndp = (struct dirent *)(void *)buf;
> +     endp = (struct dirent *)(void *)&buf[*donep];
> +
> +     /*
> +      * In-place conversion. This works because odp
> +      * is smaller than ndp, but it has to be done
> +      * in the right sequence.
> +      */
> +     for (; ndp < endp; ndp = nndp) {
> +             nndp = _DIRENT_NEXT(ndp);
> +             odp->d_fileno = (u_int32_t)ndp->d_fileno;
> +             if (odp->d_fileno != ndp->d_fileno)
> +                     return EINVAL;
> +             if (ndp->d_namlen > sizeof(odp->d_name) - 1)
> +                     return EINVAL;
> +             odp->d_namlen = ndp->d_namlen;
> +             odp->d_type = ndp->d_type;
> +             memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen);
> +             nameend = &odp->d_name[odp->d_namlen];
> +             odp->d_reclen = _DIRENT_SIZE(odp);
> +             odp = _DIRENT_NEXT(odp);
> +             memset(nameend, 0, (char *)odp - nameend);
> +     }

I suspect that code needs a load of gcc memory barriers to
stop the assignments being reordered.

I also have a personal dislike for casts that aren't absolutely
necessary in the C language.
Mostly because I've been caught out at least once by such a cast
removing a compile error (not a faffy warning from lint).

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index