Skip to content

Commit

Permalink
Fix extra trailing '\0' char in uvwasi_path_readlink
Browse files Browse the repository at this point in the history
- Close #262
  • Loading branch information
Brooooooklyn committed Apr 24, 2024
1 parent 81ac54a commit ab6faf7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/path_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,14 @@ uvwasi_errno_t uvwasi__resolve_path(const uvwasi_t* uvwasi,

link_target_len = strlen(req.ptr);
uvwasi__free(uvwasi, link_target);
link_target = uvwasi__malloc(uvwasi, link_target_len + 1);
link_target = uvwasi__malloc(uvwasi, link_target_len);
if (link_target == NULL) {
uv_fs_req_cleanup(&req);
err = UVWASI_ENOMEM;
goto exit;
}

memcpy(link_target, req.ptr, link_target_len + 1);
memcpy(link_target, req.ptr, link_target_len);
uv_fs_req_cleanup(&req);

if (1 == uvwasi__is_absolute_path(link_target, link_target_len)) {
Expand Down
2 changes: 1 addition & 1 deletion src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2199,7 +2199,7 @@ uvwasi_errno_t uvwasi_path_readlink(uvwasi_t* uvwasi,

memcpy(buf, req.ptr, len);
buf[len] = '\0';
*bufused = len + 1;
*bufused = len;
uv_fs_req_cleanup(&req);
return UVWASI_ESUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions test/test-symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(void) {
strlen(path) + 1,
&bufused);
assert(err == 0);
assert(bufused == strlen(path) + 1);
assert(bufused == strlen(path));
assert(strcmp(buf, path) == 0);

err = uvwasi_path_unlink_file(&uvwasi, 3, linkname, strlen(linkname));
Expand All @@ -79,7 +79,7 @@ int main(void) {
strlen(truncated_path) + 1,
&bufused);
assert(err == 0);
assert(bufused == strlen(truncated_path) + 1);
assert(bufused == strlen(truncated_path));
assert(strcmp(buf, truncated_path) == 0);

err = uvwasi_path_unlink_file(&uvwasi, 3, truncated_linkname, strlen(truncated_linkname));
Expand Down

0 comments on commit ab6faf7

Please sign in to comment.