From 90d1241219aabdbdcea016992b218df73e61fa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 21 Nov 2004 00:01:59 +0000 Subject: [PATCH] sys_setenv() and sys_getenv() are not only at the wrong place (that sort of stuff belongs to userland), they are completely broken, too. As a quick hack, they no longer disable interrupts, so that the env memory can be accessed almost safely (in case its valid memory at all). Please don't fix this, but remove those functions from the kernel. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10071 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/team.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/kernel/core/team.c b/src/kernel/core/team.c index 6f19b5a2d0..5ce1650742 100644 --- a/src/kernel/core/team.c +++ b/src/kernel/core/team.c @@ -1724,7 +1724,7 @@ int sys_setenv(const char *name, const char *value, int overwrite) { char var[SYS_THREAD_STRING_LENGTH_MAX]; - int state; +// int state; addr_t env_space; char **envp; int envc; @@ -1742,15 +1742,19 @@ sys_setenv(const char *name, const char *value, int overwrite) if (strlen(name) + strlen(value) + 1 >= SYS_THREAD_STRING_LENGTH_MAX) return -1; - state = disable_interrupts(); - GRAB_TEAM_LOCK(); + env_space = thread_get_current_thread()->team->user_env_base; + + // ToDo: this is totally broken! + // (temporary fix is to do this with interrupts enabled) + +// state = disable_interrupts(); +// GRAB_TEAM_LOCK(); strcpy(var, name); strncat(var, "=", SYS_THREAD_STRING_LENGTH_MAX-1); name_size = strlen(var); strncat(var, value, SYS_THREAD_STRING_LENGTH_MAX-1); - env_space = (addr_t)thread_get_current_thread()->team->user_env_base; envp = (char **)env_space; for (envc = 0; envp[envc]; envc++) { if (!strncmp(envp[envc], var, name_size)) { @@ -1797,8 +1801,8 @@ sys_setenv(const char *name, const char *value, int overwrite) } TRACE(("sys_setenv: variable set.\n")); - RELEASE_TEAM_LOCK(); - restore_interrupts(state); +// RELEASE_TEAM_LOCK(); +// restore_interrupts(state); return rc; } @@ -1809,17 +1813,21 @@ sys_getenv(const char *name, char **value) { char **envp; char *p; - int state; +// int state; int i; int len = strlen(name); int rc = -1; // ToDo: please put me out of the kernel into libroot.so! - state = disable_interrupts(); - GRAB_TEAM_LOCK(); + // ToDo: this is totally broken! + // (temporary fix is to do this with interrupts enabled) envp = (char **)thread_get_current_thread()->team->user_env_base; + +// state = disable_interrupts(); +// GRAB_TEAM_LOCK(); + for (i = 0; envp[i]; i++) { if (!strncmp(envp[i], name, len)) { p = envp[i] + len; @@ -1831,8 +1839,8 @@ sys_getenv(const char *name, char **value) } } - RELEASE_TEAM_LOCK(); - restore_interrupts(state); +// RELEASE_TEAM_LOCK(); +// restore_interrupts(state); return rc; }