@@ -186,6 +186,7 @@ char* libc_getenv(const char* variableName) {
186186 if (varNameLen == 0 ) { return NULL ; }
187187 for (int i = 0 ; i < numVariablesSet [current_pid ]; i ++ ) {
188188 if (envp [i ] == NULL ) { continue ; }
189+ if (strlen (envp [i ]) < varNameLen ) { continue ; }
189190 if (strncmp (variableName , envp [i ], varNameLen ) == 0 ) {
190191 if (strlen (envp [i ]) > varNameLen ) {
191192 if (envp [i ][varNameLen ] == '=' ) {
@@ -240,10 +241,10 @@ int ios_setenv(const char* variableName, const char* value, int overwrite) {
240241 }
241242 // Not found so far, add it to the list:
242243 int pos = numVariablesSet [current_pid ];
243- envp = realloc (envp , (numVariablesSet [current_pid ] + 2 ) * sizeof (char * ));
244- envp [pos ] = malloc (strlen (variableName ) + strlen (value ) + 2 );
245- envp [pos + 1 ] = NULL ;
246- sprintf (envp [pos ], "%s=%s" , variableName , value );
244+ environment [ current_pid ] = realloc (envp , (numVariablesSet [current_pid ] + 2 ) * sizeof (char * ));
245+ environment [ current_pid ] [pos ] = malloc (strlen (variableName ) + strlen (value ) + 2 );
246+ environment [ current_pid ] [pos + 1 ] = NULL ;
247+ sprintf (environment [ current_pid ] [pos ], "%s=%s" , variableName , value );
247248 numVariablesSet [current_pid ] += 1 ;
248249 return 0 ;
249250 } else {
0 commit comments