diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/programs/file_drop.zc | 19 | ||||
| -rwxr-xr-x | tests/test.sh | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/programs/file_drop.zc b/tests/programs/file_drop.zc new file mode 100644 index 0000000..0c0738a --- /dev/null +++ b/tests/programs/file_drop.zc @@ -0,0 +1,19 @@ +namespace; +// std.File: Host.open gives an owned file whose drop closes the descriptor at its block end (a write to it then writes nothing) +include rt, std; +fn main() { + int fd = 0 - 1; + { + std.File* f = std.Host.open("/tmp/zc-file-drop.txt", 1); + fd = f.fd; + rt.put_n(f.write("hello")); rt.put_c(' '); + rt.put_n(rt.syscall(rt.SYS_WRITE, fd, "!", 1)); rt.put_c(' '); + } + rt.put_n(rt.syscall(rt.SYS_WRITE, fd, "?", 1) <= 0); rt.put_c(' '); + char* s = rt.readfile("/tmp/zc-file-drop.txt"); + rt.put_s(s); rt.put_c(' '); + rt.free(s); + std.File* g = std.Host.open("/tmp/zc-no-such-dir/x", 1); + rt.put_n(g == 0); rt.put_c(10); + return 0; +} diff --git a/tests/test.sh b/tests/test.sh index 6dfecf1..70e12b9 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -166,6 +166,7 @@ hello world!42 256 v" "$l a full capture is still terminated inside its buffer" chk "$($vm < tests/programs/sys.zc)" "2 zy time" "$l syscalls: write, read, time" + chk "$($vm < tests/programs/file_drop.zc)" "5 1 1 hello! 1" "$l std.File: its drop closes the descriptor at block end" chk "$($vm < tests/programs/memleak.zc)" $'leak: line 8 1 words\n1' "$l memdebug names a live allocation" chk "$($vm < tests/programs/uaf.zc)" $'zc: line 10: warning: use after free: this storage\'s lifetime ended on line 9\nzy: use after free from line 7\n at <stdin>:10 in main' "$l memdebug: use after free" chk "$($vm < tests/programs/uaf_in.zc)" $'zy: use after free from line 7\n at <stdin>:11 in main' "$l memdebug: use after free through an interior pointer" |
