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
System: NetBSD 5.99.5 NetBSD 5.99.5 (GENERIC) #39: Mon Dec 
15 20:56:04 EST 2008
Architecture: x86_64
Machine: amd64
        When trying to overload the 'stat' function with LD_PRELOAD,
        the overloaded function will end up recursing.
        Compile the following program with:

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

        and then run:

          $ 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;

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

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

        assert(depth == 1);

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

        ret = _stat(pathname, buf);

        return ret;



Home | Main Index | Thread Index | Old Index