NetBSD-Bugs archive

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

lib/40220: LD_PRELOAD with dlsym(RTLD_NEXT, "stat") recursion



>Number:         40220
>Category:       lib
>Synopsis:       LD_PRELOAD with dlsym(RTLD_NEXT, "stat") recursion
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 18 14:45:00 +0000 2008
>Originator:     Jared D. McNeill
>Release:        NetBSD 5.99.5
>Organization:
        
>Environment:
        
        
System: NetBSD black.invisible.ca 5.99.5 NetBSD 5.99.5 (GENERIC) #39: Mon Dec 
15 20:56:04 EST 2008 
jmcneill%black.invisible.ca@localhost:/export/home/jmcneill/branches/HEAD/src/sys/arch/amd64/compile/GENERIC
 amd64
Architecture: x86_64
Machine: amd64
>Description:
        When trying to overload the 'stat' function with LD_PRELOAD,
        the overloaded function will end up recursing.
>How-To-Repeat:
        Compile the following program with:

          $ cc -fPIC -DPIC -shared test.c -o test.so

        and then run:

          $ LD_PRELOAD=test.so ls -l 
          stat(/etc/nsswitch.conf) depth=1
          stat(/etc/nsswitch.conf) depth=2
          assertion "depth == 1" failed: file "test.c", line 20, function "stat"
          Abort (core dumped) 

#include <sys/stat.h>
#include <assert.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static int (*_stat)(const char *, struct stat *) = NULL;

int
stat(const char *pathname, struct stat *buf)
{
        static int depth = 0;
        int ret;

        ++depth;
        (void)fprintf(stderr, "stat(%s) depth=%d\n", pathname, depth);

        assert(depth == 1);

        if (!_stat)
                _stat = dlsym(RTLD_NEXT, "stat");

        ret = _stat(pathname, buf);
        --depth;

        return ret;

}
>Fix:
        

>Unformatted:
        
        


Home | Main Index | Thread Index | Old Index