Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

LD_PRELOAD not applied to system() cmd with DASH

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
osingla
Posts: 1
Joined: 2016-02-28 15:11

LD_PRELOAD not applied to system() cmd with DASH

#1 Post by osingla »

I am using LD_PRELOAD, and I am seeing a difference between bash and dash when using the system() command.

Let's consider this simple C program:

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
system("echo $LD_PRELOAD > /tmp/blah.txt");
return 0;
}

Assuming that preload.so is installed in the system lib directory, I start this test program like this:

LD_PRELOAD=preload.so ./test
Both in bash and dash, I got:

~$ cat /tmp/blah.txt
preload.so

So far so good (the LD_PRELOAD environement variable is available to the process start by the new shell), except that the LD_PRELOAD is not applied to the command given to system when dash is the shell. I mean
- if /bin/sh points to /bin/bash, LD_PRELOAD is applied to the command given to system()
- if /bin/sh points to /bin/dash, LD_PRELOAD is NOT applied to the command given to system().

My preload.so library override open(). It is executed with the test program when bash is used (/bin/sh=/bin/bash), but not when dash is used (/bin/sh=/bin/dash).

I am guessing that bash and dash might treat the environment variables passed to execve differently, but I can not find a way with dash to have LD_PRELOAD applied to the command given to system... Unfortunately I have to use dash, and using bash is not an option.

Post Reply