1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:14:58 +00:00

LibC+DynamicLoader: Store the auxiliary vector address at startup

Previously, getauxval() got the address of the auxiliary vector by
traversing to the end of the `environ` pointer.

The assumption that the auxiliary vector comes after the environment
array is true at program startup, however the environment array may
be re-allocated and change its address during runtime which would cause
getauxval() to work with an incorrect auxiliary vector address.

To fix this, we now get the address of the auxiliary vector once in
__libc_init and store it in a libc-internal pointer which is then used
by getauxval().

Fixes #10087.
This commit is contained in:
Itamar 2021-09-20 12:13:05 +03:00 committed by Andreas Kling
parent 01900801e3
commit a3360bcee8
3 changed files with 15 additions and 4 deletions

View file

@ -19,10 +19,23 @@ __thread int errno;
char** environ;
bool __environ_is_malloced;
bool __stdio_is_initialized;
void* __auxiliary_vector;
static void __auxiliary_vector_init();
void __libc_init()
{
__auxiliary_vector_init();
__malloc_init();
__stdio_init();
}
static void __auxiliary_vector_init()
{
char** env;
for (env = environ; *env; ++env) {
}
__auxiliary_vector = (void*)++env;
}
}