Skip to content

Commit

Permalink
Safeguards in libc_getenv
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Holzschuch committed Feb 18, 2021
1 parent 3f8fed5 commit 3663be9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libc_replacement.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ inline void ios_storeThreadId(pthread_t thread) {

char* libc_getenv(const char* variableName) {
if (numVariablesSet[current_pid] > 0) {
if (variableName == NULL) { return NULL; }
char** envp = environment[current_pid];
int varNameLen = strlen(variableName);
if (varNameLen == 0) { return NULL; }
for (int i = 0; i < numVariablesSet[current_pid]; i++) {
if (envp[i] == NULL) { continue; }
if (strncmp(variableName, envp[i], varNameLen) == 0) {
if (strlen(envp[i]) > varNameLen) {
if (envp[i][varNameLen] == '=') {
Expand Down

0 comments on commit 3663be9

Please sign in to comment.