[ovs-dev] [debian 7/9] util: New function follow_symlinks().

Ben Pfaff blp at nicira.com
Wed Aug 1 17:11:23 UTC 2012


On Tue, Jul 31, 2012 at 10:06:33AM -0700, Ansis Atteka wrote:
> On Mon, Jul 30, 2012 at 3:18 PM, Ben Pfaff <blp at nicira.com> wrote:
> 
> > It will acquire its first user in an upcoming commit.
> >
> > Signed-off-by: Ben Pfaff <blp at nicira.com>

...

> > +xreadlink(const char *filename)
> > +{
> > +    size_t size;
> >
> +
> > +    for (size = 64; ; size *= 2) {
> > +        char *buf = xmalloc(size);
> > +        int retval = readlink(filename, buf, size);
> > +        int error = errno;
> > +
> > +        if (retval >= 0 && retval < size) {
> > +            buf[retval] = '\0';
> > +            return buf;
> > +        }
> > +
> > +        free(buf);
> > +        if (retval < size) {
> >
> Shouldn't size be of type ssize_t instead? Otherwise this could loop
> forever, if readlink() returned -1.

Good catch.  Thank you, that's a nasty bug.

I think that changing (retval < size) to (retval < 0) fixes the
problem too.  What do you think?



More information about the dev mailing list