2

I have a program that runs under Linux. The program crashes if a particular library exists on the system but runs normally if the library is not present. (It only seems to look for the library at first run, but doesn't care if it can't find it. If the library is present during subsequent runs, the program seems to ignore it.)

I would like to limit the libraries that the program can use at runtime. How can I achieve this?

Constraints and Possibilities:

  • I cannot modify the program.
  • I cannot upgrade or change the existing libraries on the system.
  • I can wrap the program in a shell script or call it from my own program.

Edit: It is a modified derivative of Firefox that is is not publicly available. Indeed, as Faheem Mitha suspects, it seems to be creating something in the user profile. I'm not sure what it is at this time.

  • 1
    "If the library is present during subsequent runs, the program seems to ignore it." That probably means it has saved a setting somewhere. I suggest you search for that setting. Classic Unix locations for configuration information include the file or directory ~/.prognamerc`. – Faheem Mitha May 8 '16 at 15:27
  • It may be helpful if you are able to name the program in question. – forquare May 8 '16 at 23:10
2

You can run the program in a chroot, which will force the loader to use only the libraries which you have copied into the restricted environment.

Further reading:

2

Given that the program remembers whether to use the library between runs, it must store this information in a configuration file somewhere. As suggested by Faheem Mitha your best bet is to find that configuration file and create it before running the program.

Running the program with strace should tell you what files it loads:

strace -o myprogram.strace -e open,access myprogram

If you do need to change the way the program works, then this situation calls for LD_PRELOAD. You'll need to find what library call (not system call!) the program makes to determine whether to load the file. The ltrace command might help. For example, if the program calls dlopen, override the dlopen function to return an error if the program tries to open that specific library. Warning: untested code.

#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int dlopen(const char *filename, int flags) {
    int (*original_dlopen)(const char *, int) = dlsym(RTLD_NEXT, "dlopen");
    if (!strcmp(filename, PATH_TO_HIDE)) {
        return NULL;
    }
    return original_fopen(path, mode);
}

Compile with

gcc -DPATH_TO_HIDE='"libfoo.so"' -O -Wall -fPIC -shared -o hide_libfoo.so hide_library.c -dl

Run the program as follows:

LD_PRELOAD=./hide_libfoo.so ./myprogram

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.