[gmail] Re: realpath bug

Denis Vlasenko vda.linux at googlemail.com
Sun Feb 11 14:30:45 UTC 2007


On Sunday 11 February 2007 05:55, Mike Frysinger wrote:
> On Saturday 10 February 2007, Denis Vlasenko wrote:
> > it happens so on glibc realpath() returns resolved link and
> > uclibc returns NULL but fills lfile with resolved link.
> 
> no ... glibc and uClibc both return NULL for broken symlinks

I don't understand how rev 16000 managed to work ok
with dangling symlinks, then:

        /* Create the syslog file so realpath() can work. */
        if (realpath(_PATH_LOG, lfile) != NULL) {
                unlink(lfile);
        }

        memset(&sunx, 0, sizeof(sunx));
        sunx.sun_family = AF_UNIX;
        strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path));
        sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0);
        addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
        if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) {
                bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG);
        }

unless glibc _also_ fills lfile, but returns NULL, just like uclibc.

Anyway, I am not very interested in realpath here,
I'm going to switch to readlink.

> > Patch which replaces realpath with readlink, anyone?
> 
> this wont be terribly robust as what if /dev/ is readonly and /dev/log is a 
> relative symlink ... you'd have to make sure you chroot(/dev/) first

I hope chdir("/dev") would suffice ;)
--
vda



More information about the busybox mailing list