Skip to content

Commit

Permalink
Glitch dlopen(3).
Browse files Browse the repository at this point in the history
  • Loading branch information
sobomax committed May 28, 2020
1 parent 23bfc7a commit e631ad5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/rtpp_autoglitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,35 @@ rtpp_glitch_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offs
errno = ENOMEM;
return (MAP_FAILED);
}

#include <dlfcn.h>

#undef dlopen

static const char *dlerp;

void *
rtpp_glitch_dlopen(const char *path, int mode, HERETYPEARG)
{
GLITCH_INJECT(HEREARG, glitched);
dlerp = NULL;
return (dlopen(path, mode));
glitched:
dlerp = "foo bar baz";
return (NULL);
}

#undef dlerror

const char *
rtpp_glitch_dlerror(HERETYPEARG)
{

if (dlerp != NULL) {
const char *rval;
rval = dlerp;
dlerp = NULL;
return (rval);
}
return (dlerror());
}
18 changes: 18 additions & 0 deletions src/rtpp_autoglitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,22 @@ void *rtpp_glitch_mmap(void *, size_t, int, int, int, off_t, HERETYPE);

#define mmap(addr, len, prot, flags, fd, offset) rtpp_glitch_mmap(addr, len, prot, flags, fd, offset, HEREVAL)

#include <dlfcn.h>

void *rtpp_glitch_dlopen(const char *path, int mode, HERETYPE);

#ifdef dlopen
# undef dlopen
#endif

#define dlopen(path, mode) rtpp_glitch_dlopen(path, mode, HEREVAL)

const char *rtpp_glitch_dlerror(HERETYPE);

#ifdef dlerror
# undef dlerror
#endif

#define dlerror() rtpp_glitch_dlerror(HEREVAL)

#endif /* _RTPP_AUTOGLITCH_H */

0 comments on commit e631ad5

Please sign in to comment.