authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2025-12-20 20:20:14-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:11-08:00
logbb788cd3925b7fb21e694d3586fb4c57a26005d9
treefbcea9f1c1de10f03e04d5e2a4f6d0a4dc29a3a1
parente442a0ecc23d315f99f62684c6240e7c1cb6e9ce

dirOpenFileWtf16: Disallow opening directories when requesting write permissions

This matches the behavior of POSIX

1 files changed, 4 insertions(+), 3 deletions(-)

lib/std/Io/Threaded.zig+4-3
......@@ -2917,8 +2917,9 @@ pub fn dirOpenFileWtf16(
29172917 sub_path_w: [:0]const u16,
29182918 flags: File.OpenFlags,
29192919) File.OpenError!File {
2920 if (std.mem.eql(u16, sub_path_w, &.{'.'})) return error.IsDir;
2921 if (std.mem.eql(u16, sub_path_w, &.{ '.', '.' })) return error.IsDir;
2920 const allow_directory = flags.allow_directory and !flags.isWrite();
2921 if (!allow_directory and std.mem.eql(u16, sub_path_w, &.{'.'})) return error.IsDir;
2922 if (!allow_directory and std.mem.eql(u16, sub_path_w, &.{ '.', '.' })) return error.IsDir;
29222923 const path_len_bytes = std.math.cast(u16, sub_path_w.len * 2) orelse return error.NameTooLong;
29232924 const current_thread = Thread.getCurrent(t);
29242925 const w = windows;
......@@ -2963,7 +2964,7 @@ pub fn dirOpenFileWtf16(
29632964 .OPEN,
29642965 .{
29652966 .IO = if (flags.follow_symlinks) .SYNCHRONOUS_NONALERT else .ASYNCHRONOUS,
2966 .NON_DIRECTORY_FILE = !flags.allow_directory,
2967 .NON_DIRECTORY_FILE = !allow_directory,
29672968 .OPEN_REPARSE_POINT = !flags.follow_symlinks,
29682969 },
29692970 null,