diff options
author | 2021-12-27 04:27:15 -0800 | |
---|---|---|
committer | 2021-12-27 04:27:15 -0800 | |
commit | c9c7521f4f6763dac8c5910ffcf2451c4c2f60d8 (patch) | |
tree | dd97dcdde35de34c92cc26ce19ba6897e1bac332 /src | |
parent | b455bc467da824d9e4789b0397d2480fdae95994 (diff) | |
download | bun-c9c7521f4f6763dac8c5910ffcf2451c4c2f60d8.tar.gz bun-c9c7521f4f6763dac8c5910ffcf2451c4c2f60d8.tar.zst bun-c9c7521f4f6763dac8c5910ffcf2451c4c2f60d8.zip |
Fix edgecase in `bun run` where it would choose a directory instead of a file
Diffstat (limited to 'src')
-rw-r--r-- | src/which.zig | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/which.zig b/src/which.zig index 0b8e5f1f8..e6ec2c74d 100644 --- a/src/which.zig +++ b/src/which.zig @@ -6,8 +6,11 @@ fn isValid(buf: *[std.fs.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8 std.mem.copy(u8, buf[segment.len + 1 ..], bin); buf[segment.len + 1 + bin.len ..][0] = 0; const filepath = buf[0 .. segment.len + 1 + bin.len :0]; - - std.os.accessZ(filepath, std.os.X_OK) catch return null; + var stat = std.mem.zeroes(std.os.Stat); + // we cannot use access() here even though all we want to do now here is check it is executable + // directories can be considered executable + if (std.c.stat(filepath, &stat) != 0) return null; + if (stat.mode & std.os.S_IXUSR == 0 or stat.mode & std.os.S_IFREG == 0) return null; return @intCast(u16, filepath.len); } |