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
This commit is contained in:
Axel Dörfler 2004-11-21 00:01:59 +00:00
parent 7377137f87
commit 90d1241219

View File

@ -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;
}