From beb9d33d6da42be75faed2975cf16e4acbf62be4 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Tue, 17 Nov 2020 14:05:01 +0200 Subject: [PATCH 1/3] Disallow absolute paths passed as system libraries Added OBJECT_NAME_INVALID handling in faccessatW --- lib/std/os.zig | 1 + src/main.zig | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/std/os.zig b/lib/std/os.zig index 3eb7f236c..5c97d6169 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3809,6 +3809,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32 .SUCCESS => return, .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, + .OBJECT_NAME_INVALID => return error.BadPathName, .INVALID_PARAMETER => unreachable, .ACCESS_DENIED => return error.PermissionDenied, .OBJECT_PATH_SYNTAX_BAD => unreachable, diff --git a/src/main.zig b/src/main.zig index 5e406152d..ac1b852b7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1401,6 +1401,9 @@ fn buildOutputType( _ = system_libs.orderedRemove(i); continue; } + if (std.fs.path.isAbsolute(lib_name)) { + fatal("cannot use absolute path as a system library: {}", .{lib_name}); + } i += 1; } } From f7d0a32045858be4eaba4b85d00e1bf3edbff43a Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Tue, 17 Nov 2020 14:25:52 +0200 Subject: [PATCH 2/3] Switched OBJECT_NAME_INVALID handling to unreachable in faccessatW --- lib/std/os.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 5c97d6169..ac9bbcfea 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3809,7 +3809,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32 .SUCCESS => return, .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, - .OBJECT_NAME_INVALID => return error.BadPathName, + .OBJECT_NAME_INVALID => unreachable, .INVALID_PARAMETER => unreachable, .ACCESS_DENIED => return error.PermissionDenied, .OBJECT_PATH_SYNTAX_BAD => unreachable, From 9d1816111d1d30e18b8cb43a4aa31c194fb204c4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 30 Nov 2020 18:11:07 -0700 Subject: [PATCH 3/3] build system: pass dyn lib artifacts as positionals --- lib/std/build.zig | 9 +++------ src/main.zig | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/std/build.zig b/lib/std/build.zig index c8439ca20..a658e1f05 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1980,13 +1980,10 @@ pub const LibExeObjStep = struct { try zig_args.append(other.getOutputPath()); }, .Lib => { - if (!other.is_dynamic or self.target.isWindows()) { - try zig_args.append(other.getOutputLibPath()); - } else { - const full_path_lib = other.getOutputPath(); - try zig_args.append("--library"); - try zig_args.append(full_path_lib); + const full_path_lib = other.getOutputPath(); + try zig_args.append(full_path_lib); + if (other.is_dynamic and !self.target.isWindows()) { if (fs.path.dirname(full_path_lib)) |dirname| { try zig_args.append("-rpath"); try zig_args.append(dirname); diff --git a/src/main.zig b/src/main.zig index ac1b852b7..b6858588e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1402,7 +1402,7 @@ fn buildOutputType( continue; } if (std.fs.path.isAbsolute(lib_name)) { - fatal("cannot use absolute path as a system library: {}", .{lib_name}); + fatal("cannot use absolute path as a system library: {s}", .{lib_name}); } i += 1; }