mirror of
https://github.com/ziglang/zig.git
synced 2025-12-07 14:53:08 +00:00
std: avoid references that trigger compile errors
Note that the `_ = Address` statements in tests previously were a nop, and now actually check that the type is valid. However, on WASI, the type is *not* valid.
This commit is contained in:
parent
00da182e68
commit
eae9aa800e
@ -17,12 +17,15 @@ pub const DynLib = struct {
|
|||||||
DlDynLib,
|
DlDynLib,
|
||||||
.windows => WindowsDynLib,
|
.windows => WindowsDynLib,
|
||||||
.macos, .tvos, .watchos, .ios, .visionos, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris, .illumos => DlDynLib,
|
.macos, .tvos, .watchos, .ios, .visionos, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris, .illumos => DlDynLib,
|
||||||
else => @compileError("unsupported platform"),
|
else => struct {
|
||||||
|
const open = @compileError("unsupported platform");
|
||||||
|
const openZ = @compileError("unsupported platform");
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
inner: InnerType,
|
inner: InnerType,
|
||||||
|
|
||||||
pub const Error = ElfDynLib.Error || DlDynLib.Error || WindowsDynLib.Error;
|
pub const Error = ElfDynLibError || DlDynLibError || WindowsDynLibError;
|
||||||
|
|
||||||
/// Trusts the file. Malicious file will be able to execute arbitrary code.
|
/// Trusts the file. Malicious file will be able to execute arbitrary code.
|
||||||
pub fn open(path: []const u8) Error!DynLib {
|
pub fn open(path: []const u8) Error!DynLib {
|
||||||
@ -122,6 +125,18 @@ pub fn linkmap_iterator(phdrs: []elf.Phdr) error{InvalidExe}!LinkMap.Iterator {
|
|||||||
return .{ .current = link_map_ptr };
|
return .{ .current = link_map_ptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Separated to avoid referencing `ElfDynLib`, because its field types may not
|
||||||
|
/// be valid on other targets.
|
||||||
|
const ElfDynLibError = error{
|
||||||
|
FileTooBig,
|
||||||
|
NotElfFile,
|
||||||
|
NotDynamicLibrary,
|
||||||
|
MissingDynamicLinkingInformation,
|
||||||
|
ElfStringSectionNotFound,
|
||||||
|
ElfSymSectionNotFound,
|
||||||
|
ElfHashTableNotFound,
|
||||||
|
} || posix.OpenError || posix.MMapError;
|
||||||
|
|
||||||
pub const ElfDynLib = struct {
|
pub const ElfDynLib = struct {
|
||||||
strings: [*:0]u8,
|
strings: [*:0]u8,
|
||||||
syms: [*]elf.Sym,
|
syms: [*]elf.Sym,
|
||||||
@ -130,15 +145,7 @@ pub const ElfDynLib = struct {
|
|||||||
verdef: ?*elf.Verdef,
|
verdef: ?*elf.Verdef,
|
||||||
memory: []align(mem.page_size) u8,
|
memory: []align(mem.page_size) u8,
|
||||||
|
|
||||||
pub const Error = error{
|
pub const Error = ElfDynLibError;
|
||||||
FileTooBig,
|
|
||||||
NotElfFile,
|
|
||||||
NotDynamicLibrary,
|
|
||||||
MissingDynamicLinkingInformation,
|
|
||||||
ElfStringSectionNotFound,
|
|
||||||
ElfSymSectionNotFound,
|
|
||||||
ElfHashTableNotFound,
|
|
||||||
} || posix.OpenError || posix.MMapError;
|
|
||||||
|
|
||||||
/// Trusts the file. Malicious file will be able to execute arbitrary code.
|
/// Trusts the file. Malicious file will be able to execute arbitrary code.
|
||||||
pub fn open(path: []const u8) Error!ElfDynLib {
|
pub fn open(path: []const u8) Error!ElfDynLib {
|
||||||
@ -350,11 +357,15 @@ test "ElfDynLib" {
|
|||||||
try testing.expectError(error.FileNotFound, ElfDynLib.open("invalid_so.so"));
|
try testing.expectError(error.FileNotFound, ElfDynLib.open("invalid_so.so"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Separated to avoid referencing `WindowsDynLib`, because its field types may not
|
||||||
|
/// be valid on other targets.
|
||||||
|
const WindowsDynLibError = error{
|
||||||
|
FileNotFound,
|
||||||
|
InvalidPath,
|
||||||
|
} || windows.LoadLibraryError;
|
||||||
|
|
||||||
pub const WindowsDynLib = struct {
|
pub const WindowsDynLib = struct {
|
||||||
pub const Error = error{
|
pub const Error = WindowsDynLibError;
|
||||||
FileNotFound,
|
|
||||||
InvalidPath,
|
|
||||||
} || windows.LoadLibraryError;
|
|
||||||
|
|
||||||
dll: windows.HMODULE,
|
dll: windows.HMODULE,
|
||||||
|
|
||||||
@ -413,8 +424,12 @@ pub const WindowsDynLib = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Separated to avoid referencing `DlDynLib`, because its field types may not
|
||||||
|
/// be valid on other targets.
|
||||||
|
const DlDynLibError = error{ FileNotFound, NameTooLong };
|
||||||
|
|
||||||
pub const DlDynLib = struct {
|
pub const DlDynLib = struct {
|
||||||
pub const Error = error{ FileNotFound, NameTooLong };
|
pub const Error = DlDynLibError;
|
||||||
|
|
||||||
handle: *anyopaque,
|
handle: *anyopaque,
|
||||||
|
|
||||||
|
|||||||
@ -311,13 +311,13 @@ const builtin = @import("builtin");
|
|||||||
const std = @import("std.zig");
|
const std = @import("std.zig");
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = Client;
|
|
||||||
_ = Method;
|
|
||||||
_ = Server;
|
|
||||||
_ = Status;
|
|
||||||
_ = HeadParser;
|
|
||||||
_ = ChunkParser;
|
|
||||||
if (builtin.os.tag != .wasi) {
|
if (builtin.os.tag != .wasi) {
|
||||||
|
_ = Client;
|
||||||
|
_ = Method;
|
||||||
|
_ = Server;
|
||||||
|
_ = Status;
|
||||||
|
_ = HeadParser;
|
||||||
|
_ = ChunkParser;
|
||||||
_ = @import("http/test.zig");
|
_ = @import("http/test.zig");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1930,8 +1930,10 @@ pub const Server = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = @import("net/test.zig");
|
if (builtin.os.tag != .wasi) {
|
||||||
_ = Server;
|
_ = Server;
|
||||||
_ = Stream;
|
_ = Stream;
|
||||||
_ = Address;
|
_ = Address;
|
||||||
|
_ = @import("net/test.zig");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user