Skip to content

Commit fe7cfaa

Browse files
authored
Fix use of uninitialized stack data in test_unistd_dup (emscripten-core#17252)
This was causing it to fail under ASAN.
1 parent 3b91cc3 commit fe7cfaa

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

tests/unistd/dup.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <fcntl.h>
1212
#include <emscripten.h>
1313
#include <assert.h>
14+
#include <string.h>
1415

1516

1617
int main() {
@@ -50,18 +51,20 @@ int main() {
5051
printf("\n");
5152
errno = 0;
5253

53-
5454
printf("DUP2 pipe\n");
5555
int p[2];
5656
pipe(p);
5757
int g = dup2(p[0], 7);
58-
write(p[1], "abc\n", 3);
59-
char buf[5];
60-
read(g, buf, 5);
61-
// should print "buf: abc\n"
58+
int rtn = write(p[1], "abc", 3);
59+
assert(rtn == 3);
60+
char buf[5] = {0};
61+
rtn = read(g, buf, 5);
62+
assert(rtn == 3);
6263
printf("buf: %s\n", buf);
64+
assert(strcmp(buf, "abc") == 0);
65+
printf("\n");
6366

64-
67+
printf("DUP2 shared seek position\n");
6568
int fd1 = open("./blah.txt", O_RDWR | O_CREAT | O_EXCL, 0600);
6669
int fd2 = dup(fd1);
6770
int n = write(fd1, "abcabc\n", 7);

tests/unistd/dup.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ close(f): -1
2121

2222
DUP2 pipe
2323
buf: abc
24+
25+
DUP2 shared seek position

0 commit comments

Comments
 (0)