mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
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.
41 lines
660 B
C++
41 lines
660 B
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Types.h>
|
|
#include <assert.h>
|
|
#include <sys/internals.h>
|
|
#include <unistd.h>
|
|
|
|
extern "C" {
|
|
|
|
#ifdef NO_TLS
|
|
int errno;
|
|
#else
|
|
__thread int errno;
|
|
#endif
|
|
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;
|
|
}
|
|
}
|