zig
zig copied to clipboard
Crash (likely undefined behavior) of `std.process.Child.run` in `ReleaseFast` mode only
Zig Version
0.14.0-dev.121+ab4c461b7
Steps to Reproduce and Observed Behavior
std.process.Child.run crashes, only in ReleaseFast mode, when trying to close /dev/null.
Here how i'm using it: https://github.com/buzz-language/buzz/blob/execute/src/lib/buzz_os.zig#L192-L273
Here's the trace (broke down the return statement into several lines to see exactly where it failed):
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x100650d70)
frame #0: 0x0000000100650d70 libos.dylib`buzz_os.execute [inlined] posix.errno__anon_6988(rc=<unavailable>) at posix.zig:221:36 [opt]
218 pub fn errno(rc: anytype) E {
219 if (use_libc) {
220 return if (rc == -1) blk: {
-> 221 const en = std.c._errno();
222 break :blk @enumFromInt(en.*);
223 } else .SUCCESS;
224 }
warning: libos.dylib was compiled with optimization - stepping may behave oddly; variables may not be available.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x100650d70)
* frame #0: 0x0000000100650d70 libos.dylib`buzz_os.execute [inlined] posix.errno__anon_6988(rc=<unavailable>) at posix.zig:221:36 [opt]
frame #1: 0x0000000100650d6c libos.dylib`buzz_os.execute [inlined] posix.close(fd=8) at posix.zig:247:22 [opt]
frame #2: 0x0000000100650d64 libos.dylib`buzz_os.execute [inlined] process.Child.spawnPosix at Child.zig:585:36 [opt]
frame #3: 0x0000000100650c20 libos.dylib`buzz_os.execute [inlined] process.Child.spawn at Child.zig:242:31 [opt]
frame #4: 0x0000000100650c20 libos.dylib`buzz_os.execute [inlined] process.Child.run(args=process.Child.run__struct_2437 @ 0x0000600003bc8e60) at Child.zig:398:20 [opt]
frame #5: 0x0000000100650c20 libos.dylib`buzz_os.execute(ctx=0x000000016fdfcfb8) at buzz_os.zig:217:41 [opt]
Once buzz built on the execute branch, you can reproduce the error by running the REPL:
λ giann [~/git/buzz] at execute !?
→ buzz [85a32cb]
👨🚀 buzz 0.5.0-85a32cb Copyright (C) 2021-present Benoit Giannangeli
>>> import "os";
>>> os.execute(["ls", "-l"]);
[1] 9015 trace trap buzz
Expected Behavior
Not crashing or a least exit with a useful error message