Skip to content

Commit

Permalink
fix: Return correct length of string in fd_prestat_get (nodejs#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed Apr 22, 2023
1 parent 53509c3 commit 8fe8eec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ uvwasi_errno_t uvwasi_fd_prestat_get(uvwasi_t* uvwasi,
}

buf->pr_type = UVWASI_PREOPENTYPE_DIR;
buf->u.dir.pr_name_len = strlen(wrap->path) + 1;
buf->u.dir.pr_name_len = strlen(wrap->path);
err = UVWASI_ESUCCESS;
exit:
uv_mutex_unlock(&wrap->mutex);
Expand Down Expand Up @@ -1156,7 +1156,7 @@ uvwasi_errno_t uvwasi_fd_prestat_dir_name(uvwasi_t* uvwasi,
goto exit;
}

size = strlen(wrap->path) + 1;
size = strlen(wrap->path);
if (size > (size_t) path_len) {
err = UVWASI_ENOBUFS;
goto exit;
Expand Down
7 changes: 4 additions & 3 deletions test/test-fd-prestat-dir-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ int main(void) {
assert(err == 0);
assert(prestat.pr_type == UVWASI_PREOPENTYPE_DIR);
assert(prestat.u.dir.pr_name_len ==
strlen(init_options.preopens[0].mapped_path) + 1);
strlen(init_options.preopens[0].mapped_path));

/* Verify uvwasi_fd_prestat_dir_name(). */
prestat_buf_size = prestat.u.dir.pr_name_len + 1;
prestat_buf = malloc(prestat_buf_size);
prestat_buf_size = prestat.u.dir.pr_name_len;
prestat_buf = malloc(prestat_buf_size + 1);
assert(prestat_buf != NULL);
err = uvwasi_fd_prestat_dir_name(&uvwasi,
3,
prestat_buf,
prestat_buf_size);
prestat_buf[prestat_buf_size] = '\0';
assert(err == 0);
assert(strcmp(prestat_buf, init_options.preopens[0].mapped_path) == 0);
free(prestat_buf);
Expand Down

0 comments on commit 8fe8eec

Please sign in to comment.