aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorRyan Liptak <squeek502@hotmail.com>2025-12-20 20:20:14 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:11 -0800
commitbb788cd3925b7fb21e694d3586fb4c57a26005d9 (patch)
treefbcea9f1c1de10f03e04d5e2a4f6d0a4dc29a3a1 /lib/std
parente442a0ecc23d315f99f62684c6240e7c1cb6e9ce (diff)
downloadzig-bb788cd3925b7fb21e694d3586fb4c57a26005d9.tar.gz
zig-bb788cd3925b7fb21e694d3586fb4c57a26005d9.zip
dirOpenFileWtf16: Disallow opening directories when requesting write permissions
This matches the behavior of POSIX
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Io/Threaded.zig7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
index a586ae2b38..10be573452 100644
--- a/lib/std/Io/Threaded.zig
+++ b/lib/std/Io/Threaded.zig
@@ -2917,8 +2917,9 @@ pub fn dirOpenFileWtf16(
sub_path_w: [:0]const u16,
flags: File.OpenFlags,
) File.OpenError!File {
- if (std.mem.eql(u16, sub_path_w, &.{'.'})) return error.IsDir;
- if (std.mem.eql(u16, sub_path_w, &.{ '.', '.' })) return error.IsDir;
+ const allow_directory = flags.allow_directory and !flags.isWrite();
+ if (!allow_directory and std.mem.eql(u16, sub_path_w, &.{'.'})) return error.IsDir;
+ if (!allow_directory and std.mem.eql(u16, sub_path_w, &.{ '.', '.' })) return error.IsDir;
const path_len_bytes = std.math.cast(u16, sub_path_w.len * 2) orelse return error.NameTooLong;
const current_thread = Thread.getCurrent(t);
const w = windows;
@@ -2963,7 +2964,7 @@ pub fn dirOpenFileWtf16(
.OPEN,
.{
.IO = if (flags.follow_symlinks) .SYNCHRONOUS_NONALERT else .ASYNCHRONOUS,
- .NON_DIRECTORY_FILE = !flags.allow_directory,
+ .NON_DIRECTORY_FILE = !allow_directory,
.OPEN_REPARSE_POINT = !flags.follow_symlinks,
},
null,