Question
You should be able to observe two different behaviours in the scenarios described above, even though you are running the same program. Note the different
Step 1. First, we will see how these environment variables influence the behaviour of dynamic loader/linker when running a normal program. Please follow these steps:
If we run a program that uses our dynamically linked library it will override the default sleep() function in libc and print our text out instead:
#include stdio.h> void sleep (int s) { /* If this is invoked by a privileged program, you can do damage here! */ printf("I am not sleeping! "); } |
Code Listing 6: Dynamic library - sleep() call
$ gcc -fPIC -g -c mylib.c
$ gcc -shared -o libmylib.so.1.0.1 mylib.o -lc
$ export LD_PRELOAD=./libmylib.so.1.0.1
/* task8.c */
int main()
{ sleep(1); return 0;
}
Code Listing 7: Program to invoke sleep() system call.
Step 2. After you have done the above, please run the task8 executables under the following conditions, and observe what happens. (NOTE: pay close attention to the instructions!). If the program picks up our dynamic library, it should print our text. If it uses the default system sleep() library, then it will sleep for 1 second and return the CLI prompt without printing anything.
Export the LD_PRELOAD environment variable again in the root account and run the task8-d program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started