Possible bug with dlsym and LD_PRELOAD

Paul Millar paul.millar@desy.de
Mon Aug 27 11:22:00 GMT 2012


Hi Ángel,

On 08/22/2012 12:20 AM, Ángel González wrote:
> Have you tried simply replacing dlsym() ?
> There you could place yourself in front of any call.

No, I hadn't thought of that.

Although this solves the immediate problem of intercepting these calls, 
it introduces a new problem; specifically, the code now can't call 
dlsym(RTLD_NEXT, ...) in the wrapping library.  Any attempt to call this 
function is mapping (by LD_PRELOAD) to the intercepting implementation 
in the wrapping library.

Currently, although the code intercepts generic functions, like read(2) 
and write(2), it fakes only those calls that involve a socket.  Those 
involving stdin/stdout/stderr and opened files are passed onto the 
underlying OS.  This helps keep down the complexity.

With a custom dlsym function, the code intercepting write(2) now can't 
call the real write(2) but must always deliver a fake reply.  This 
greatly increases the complexity of the system: the library now needs to 
provide a fairly complete POSIX implementation.

So, although this solves the problem, I think I'll carry on looking for 
alternatives.

Cheers,

Paul.



More information about the Libc-help mailing list