@@ -186,6 +186,7 @@ char* libc_getenv(const char* variableName) {
186
186
if (varNameLen == 0 ) { return NULL ; }
187
187
for (int i = 0 ; i < numVariablesSet [current_pid ]; i ++ ) {
188
188
if (envp [i ] == NULL ) { continue ; }
189
+ if (strlen (envp [i ]) < varNameLen ) { continue ; }
189
190
if (strncmp (variableName , envp [i ], varNameLen ) == 0 ) {
190
191
if (strlen (envp [i ]) > varNameLen ) {
191
192
if (envp [i ][varNameLen ] == '=' ) {
@@ -240,10 +241,10 @@ int ios_setenv(const char* variableName, const char* value, int overwrite) {
240
241
}
241
242
// Not found so far, add it to the list:
242
243
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 );
247
248
numVariablesSet [current_pid ] += 1 ;
248
249
return 0 ;
249
250
} else {
0 commit comments