aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Carter Snook <cartersnook04@gmail.com> 2022-10-24 00:14:37 -0500
committerGravatar GitHub <noreply@github.com> 2022-10-23 22:14:37 -0700
commit223ce77ecafe16bf7b314817e06780182dc88c3c (patch)
tree6e824860b27cd840b6bbfda4e350ceab212c3185
parentec9787770eec73201fae7ee60982e1df93391525 (diff)
downloadbun-223ce77ecafe16bf7b314817e06780182dc88c3c.tar.gz
bun-223ce77ecafe16bf7b314817e06780182dc88c3c.tar.zst
bun-223ce77ecafe16bf7b314817e06780182dc88c3c.zip
fix(web): stop segfault on invalid fd error (#1386)
-rw-r--r--src/bun.js/api/server.zig6
-rw-r--r--src/bun.js/node/types.zig10
2 files changed, 15 insertions, 1 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 9021ef7d5..5d851bcc6 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -1142,7 +1142,11 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
const stat: std.os.Stat = switch (JSC.Node.Syscall.fstat(fd)) {
.result => |result| result,
.err => |err| {
- this.runErrorHandler(err.withPath(file.pathlike.path.slice()).toSystemError().toErrorInstance(
+ var out = std.ArrayList(u8).initCapacity(this.allocator, 16) catch unreachable;
+ std.fmt.format(out.writer(), "{}", .{file.pathlike}) catch {};
+ var zig_string = ZigString.init(out.items);
+ zig_string.mark();
+ this.runErrorHandler(err.withPath(zig_string.toSliceFast(this.allocator).slice()).toSystemError().toErrorInstance(
this.server.globalThis,
));
if (auto_close) {
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index 5e54066b9..526e33f29 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -801,6 +801,16 @@ pub const PathOrFileDescriptor = union(Tag) {
};
}
+ pub fn format(this: PathOrFileDescriptor, comptime fmt: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
+ if (fmt.len != 0 and fmt != "s") {
+ @compileError("Unsupported format argument: '" ++ fmt ++ "'.");
+ }
+ switch (this) {
+ .path => |p| try writer.writeAll(p.slice()),
+ .fd => |fd| try writer.print("{d}", .{fd}),
+ }
+ }
+
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?PathOrFileDescriptor {
const first = arguments.next() orelse return null;