From: John Hodge Date: Fri, 18 Jun 2010 09:32:02 +0000 (+0800) Subject: Fixed the EnvP array passed to Proc_StartUser not being NULL terminated X-Git-Tag: rel0.06~145 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=e29b02ca55d580b2f7f10d1093c3d6ad1bc59458;p=tpg%2Facess2.git Fixed the EnvP array passed to Proc_StartUser not being NULL terminated --- diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 43a88e38..b6dbfdd5 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -587,7 +587,6 @@ Uint Proc_MakeUserStack(void) return base + USER_STACK_SZ; } - /** * \fn void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize) * \brief Starts a user task @@ -599,19 +598,30 @@ void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char ** Uint delta; Uint16 ss, cs; - LOG("stack = 0x%x", stack); + //Log("stack = %p", stack); // Copy Arguments - stack = (void*)( (Uint)stack - DataSize ); + stack -= DataSize/sizeof(*stack); memcpy( stack, ArgV, DataSize ); - // Adjust Arguments and environment - delta = (Uint)stack - (Uint)ArgV; - ArgV = (char**)stack; - for( i = 0; ArgV[i]; i++ ) ArgV[i] += delta; - i ++; - EnvP = &ArgV[i]; - for( i = 0; EnvP[i]; i++ ) EnvP[i] += delta; + //Log("stack = %p", stack); + + if( DataSize ) + { + // Adjust Arguments and environment + delta = (Uint)stack - (Uint)ArgV; + ArgV = (char**)stack; + for( i = 0; ArgV[i]; i++ ) + ArgV[i] += delta; + i ++; + + // Do we care about EnvP? + if( EnvP ) { + EnvP = &ArgV[i]; + for( i = 0; EnvP[i]; i++ ) + EnvP[i] += delta; + } + } // User Mode Segments ss = 0x23; cs = 0x1B; diff --git a/Kernel/binary.c b/Kernel/binary.c index 9455a626..de4d813b 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -142,6 +142,7 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP) strcpy(envpSaved[i], EnvP[i]); strBuf += strlen(EnvP[i])+1; } + envpSaved[i] = NULL; savedFile = malloc(strlen(File)+1); strcpy(savedFile, File);