Skip to content

Commit 3727959

Browse files
authored
Fix some minor issues found from static analysis (WebAssembly#765)
This commit fixes two separate issues identified by some static analysis of wasi-libc, notably: * A missing null-check from an allocation. * An erroneous `__wasilibc_cwd_unlock()` in `chdir.c` affecting threaded targets.
1 parent e8438cc commit 3727959

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

libc-bottom-half/sources/__wasilibc_initialize_environ.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void __wasilibc_initialize_environ(void) {
108108
// Allocate memory for the array of pointers. This uses `calloc` both to
109109
// handle overflow and to initialize the NULL pointer at the end.
110110
char **environ_ptrs = calloc(num_ptrs, sizeof(char *));
111+
if (!environ_ptrs)
112+
goto software;
111113

112114
// Copy the environment variables
113115
for (size_t i = 0; i < environ_count; i++) {

libc-bottom-half/sources/chdir.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ static const char *make_absolute(const char *path) {
101101
__wasilibc_cwd_lock();
102102
size_t cwd_len = strlen(__wasilibc_cwd);
103103
size_t path_len = path ? strlen(path) : 0;
104-
__wasilibc_cwd_unlock();
105104
int need_slash = __wasilibc_cwd[cwd_len - 1] == '/' ? 0 : 1;
106105
size_t alloc_len = cwd_len + path_len + 1 + need_slash;
107106
if (alloc_len > make_absolute_len) {

0 commit comments

Comments
 (0)