Skip to content

Commit

Permalink
Fix UB in test_unistd_write_broken_link (#23125)
Browse files Browse the repository at this point in the history
The test was failing under ASan because no null byte was being
read from the file, so the strlen inside printf was running
off the buffer. It just happened to work on non-ASan because
wasm memory is initialized to zero.
  • Loading branch information
dschuff authored Dec 11, 2024
1 parent fb77f78 commit 1171ada
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/unistd/test_unistd_write_broken_link.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
Expand All @@ -16,15 +17,19 @@ int main() {
int target_fd = open("link_target", O_RDONLY);
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
char buf[10];
read(target_fd, buf, 10);
memset(buf, 0, 10);
size_t r = read(target_fd, buf, 10);
assert(r == 3);
printf("buf: '%s'\n", buf);
close(target_fd);
}
{
int target_fd = open("link_source", O_RDONLY);
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
char buf[10];
read(target_fd, buf, 10);
memset(buf, 0, 10);
size_t r = read(target_fd, buf, 10);
assert(r == 3);
printf("buf: '%s'\n", buf);
close(target_fd);
}
Expand Down

0 comments on commit 1171ada

Please sign in to comment.