summaryrefslogtreecommitdiff
path: root/src/wrapper
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-11-18 07:59:05 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-11-18 07:59:05 +0200
commitc54ec039eb0ea6e6e74025fca2ee2de6ab5b79e5 (patch)
tree9d0caf95c2e1dbcd06346695bf778181cf576c2d /src/wrapper
parent38966a58203355d6040e9487f07d8f8289333ebe (diff)
copy symbols in wrapper_create
We don't know the lifetime of the const char* input, so lets copy it. this is quite naive, solution for now, but should be good enough as this is mainly for debugging. Maybe leter do something more fancy to avoid copies from symbols that came from linker for example, and use hashtable to avoid duplication.
Diffstat (limited to 'src/wrapper')
-rw-r--r--src/wrapper/wrapper.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/wrapper/wrapper.c b/src/wrapper/wrapper.c
index b3249b6..9b2ed96 100644
--- a/src/wrapper/wrapper.c
+++ b/src/wrapper/wrapper.c
@@ -103,13 +103,18 @@ wrapper_create(const char *const symbol, void *function)
return NULL;
}
+ const size_t len = strlen(symbol) + 1;
+ char *copy = malloc(len);
+ assert(copy && "welp, malloc failed");
+ memcpy(copy, symbol, len);
+
#ifdef WRAPPER_TRACE
const size_t sz = &wrapper_end - &wrapper_start;
unsigned char *fun = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
assert(fun != MAP_FAILED);
memcpy(fun, &wrapper_start, sz);
#ifdef ANDROID_X86_LINKER
- memcpy(fun + (&wrapper_symbol - &wrapper_start) + 1, &symbol, sizeof(symbol));
+ memcpy(fun + (&wrapper_symbol - &wrapper_start) + 1, &copy, sizeof(symbol));
memcpy(fun + (&wrapper_trace - &wrapper_start) + 1, (uintptr_t[]){ (uintptr_t)trace }, sizeof(uintptr_t));
memcpy(fun + (&wrapper_call - &wrapper_start) + 1, &function, sizeof(function));
#else