diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2022-03-07 16:24:04 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2022-03-08 17:37:09 +0100 |
| commit | ff31d0b0233dffa7ec2e05bc1a4f849831fe63f3 (patch) | |
| tree | da244effaa33c1ff8cb5741f5d966245ece75be2 /src | |
| parent | 652e8318e66d3a7eea6257aca4b3fadf27c0522c (diff) | |
| download | box64-ff31d0b0233dffa7ec2e05bc1a4f849831fe63f3.tar.gz box64-ff31d0b0233dffa7ec2e05bc1a4f849831fe63f3.zip | |
Better handling of environ and envp in execve
Diffstat (limited to 'src')
| -rwxr-xr-x | src/main.c | 10 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibc.c | 4 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibc_private.h | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c index 34d2f58d..1e702aeb 100755 --- a/src/main.c +++ b/src/main.c @@ -584,12 +584,12 @@ void LoadEnvPath(path_collection_t *col, const char* defpath, const char* env) } EXPORTDYN -int CountEnv(const char** env) +int CountEnv(char** env) { // count, but remove all BOX64_* environnement // also remove PATH and LD_LIBRARY_PATH // but add 2 for default BOX64_PATH and BOX64_LD_LIBRARY_PATH - const char** p = env; + char** p = env; int c = 0; while(*p) { if(strncmp(*p, "BOX64_", 6)!=0) @@ -600,11 +600,11 @@ int CountEnv(const char** env) return c+2; } EXPORTDYN -int GatherEnv(char*** dest, const char** env, const char* prog) +int GatherEnv(char*** dest, char** env, char* prog) { // Add all but BOX64_* environnement // but add 2 for default BOX64_PATH and BOX64_LD_LIBRARY_PATH - const char** p = env; + char** p = env; int idx = 0; int path = 0; int ld_path = 0; @@ -907,7 +907,7 @@ static void free_contextargv() free(my_context->argv[i]); } -const char **environ __attribute__((weak)) = NULL; +extern char** environ; int main(int argc, const char **argv, const char **env) { init_auxval(argc, argv, environ?environ:env); diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 61429120..a3828b96 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -1697,6 +1697,10 @@ EXPORT int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], ch int self = isProcSelf(path, "exe"); int x64 = FileIsX64ELF(path); int x86 = my_context->box86path?FileIsX86ELF(path):0; + // hack to update the environ var if needed + if(envp == my_context->envv && environ) { + envp = environ; + } printf_log(LOG_DEBUG, "execve(\"%s\", %p, %p) is x64=%d x86=%d\n", path, argv, envp, x64, x86); #if 1 if (x64 || x86 || self) { diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index bdcca88d..4618c139 100755 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -250,8 +250,8 @@ GOW(endttyent, iFv) GO(endusershell, vFv) GOW(endutent, vFv) GO(endutxent, vFv) -DATA(environ, sizeof(void*)) -DATAB(__environ, sizeof(void*)) +DATAM(environ, sizeof(void*)) +DATAM(__environ, sizeof(void*)) GO(envz_add, iFpppp) GO(envz_entry, pFpLp) GO(envz_get, pFpLp) |