Skip to content

Commit 1171ada

Browse files
authored
Fix UB in test_unistd_write_broken_link (#23125)
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.
1 parent fb77f78 commit 1171ada

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: test/unistd/test_unistd_write_broken_link.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <assert.h>
12
#include <errno.h>
23
#include <fcntl.h>
34
#include <stdio.h>
@@ -16,15 +17,19 @@ int main() {
1617
int target_fd = open("link_target", O_RDONLY);
1718
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
1819
char buf[10];
19-
read(target_fd, buf, 10);
20+
memset(buf, 0, 10);
21+
size_t r = read(target_fd, buf, 10);
22+
assert(r == 3);
2023
printf("buf: '%s'\n", buf);
2124
close(target_fd);
2225
}
2326
{
2427
int target_fd = open("link_source", O_RDONLY);
2528
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
2629
char buf[10];
27-
read(target_fd, buf, 10);
30+
memset(buf, 0, 10);
31+
size_t r = read(target_fd, buf, 10);
32+
assert(r == 3);
2833
printf("buf: '%s'\n", buf);
2934
close(target_fd);
3035
}

0 commit comments

Comments
 (0)