Skip to content

Commit

Permalink
Merge pull request #5 from cassandracomar/main
Browse files Browse the repository at this point in the history
fix: segfault when getcwd is called with null buf
  • Loading branch information
Thesola10 committed Aug 12, 2024
2 parents b0f70b8 + 8114bfc commit a2bd8d0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions trivial_replacements.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "common.h"
#include <string.h>

/**
* @file trivial_replacements.c
Expand Down Expand Up @@ -309,10 +310,16 @@ ENDSUBST

SUBST(char const *, getcwd, (char *buf, size_t size))
pthread_mutex_unlock(&_lock);
getcwd(buf, size);
char const *cwd = getcwd(buf, size);
pthread_mutex_lock(&_lock);
strlcpy(buf, rewrite_path_rev(buf), size);
buf;
char *nbuf;
if (buf == NULL) {
nbuf = strdup(cwd);
} else {
nbuf = buf;
}
strlcpy(nbuf, rewrite_path_rev(nbuf), size);
nbuf;
ENDSUBST

SUBST(DIR *, opendir, (char const *path))
Expand Down

0 comments on commit a2bd8d0

Please sign in to comment.