aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-30 23:13:17 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-30 23:13:17 -0700
commitdc28f5c3ec61a525d45d9f07a666e62f6598ed0a (patch)
tree45daf6a6a98bc0828412fd807eebd2e84e34511a /lib
parent351b57497b1cf2ea6ee72a3c7cfdb84b924bb368 (diff)
parent557eb414eee96201d1ae01b15ebf8955eca1da6d (diff)
downloadzig-dc28f5c3ec61a525d45d9f07a666e62f6598ed0a.tar.gz
zig-dc28f5c3ec61a525d45d9f07a666e62f6598ed0a.zip
Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts: lib/std/crypto/25519/field.zig lib/std/crypto/poly1305.zig I had resolved those by removing `comptime` but master branch decided to make the parameters `comptime`. This also pulls in the updated default `zig build` install directory.
Diffstat (limited to 'lib')
-rw-r--r--lib/std/build.zig3
-rw-r--r--lib/std/compress/deflate.zig18
-rw-r--r--lib/std/crypto/25519/field.zig2
-rw-r--r--lib/std/crypto/poly1305.zig2
-rw-r--r--lib/std/os.zig10
-rw-r--r--lib/std/special/build_runner.zig6
6 files changed, 31 insertions, 10 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig
index ff2a16d2b9..4eeb4aad4d 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -195,7 +195,8 @@ pub const Builder = struct {
self.install_prefix = install_prefix orelse "/usr";
self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;
} else {
- self.install_prefix = install_prefix orelse self.cache_root;
+ self.install_prefix = install_prefix orelse
+ (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
self.install_path = self.install_prefix;
}
self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
diff --git a/lib/std/compress/deflate.zig b/lib/std/compress/deflate.zig
index e680dc9e6f..09e162933c 100644
--- a/lib/std/compress/deflate.zig
+++ b/lib/std/compress/deflate.zig
@@ -384,6 +384,8 @@ pub fn InflateStream(comptime ReaderType: type) type {
const last_length = lengths[i - 1];
const repeat = 3 + (try self.readBits(2));
const last_index = i + repeat;
+ if (last_index > lengths.len)
+ return error.InvalidLength;
while (i < last_index) : (i += 1) {
lengths[i] = last_length;
}
@@ -655,3 +657,19 @@ pub fn InflateStream(comptime ReaderType: type) type {
pub fn inflateStream(reader: anytype, window_slice: []u8) InflateStream(@TypeOf(reader)) {
return InflateStream(@TypeOf(reader)).init(reader, window_slice);
}
+
+test "lengths overflow" {
+ // malformed final dynamic block, tries to write 321 code lengths (MAXCODES is 316)
+ // f dy hlit hdist hclen 16 17 18 0 (18) x138 (18) x138 (18) x39 (16) x6
+ // 1 10 11101 11101 0000 010 010 010 010 (11) 1111111 (11) 1111111 (11) 0011100 (01) 11
+ const stream = [_]u8{
+ 0b11101101, 0b00011101, 0b00100100, 0b11101001, 0b11111111, 0b11111111, 0b00111001, 0b00001110
+ };
+
+ const reader = std.io.fixedBufferStream(&stream).reader();
+ var window: [0x8000]u8 = undefined;
+ var inflate = inflateStream(reader, &window);
+
+ var buf: [1]u8 = undefined;
+ std.testing.expectError(error.InvalidLength, inflate.read(&buf));
+}
diff --git a/lib/std/crypto/25519/field.zig b/lib/std/crypto/25519/field.zig
index 57371d8290..3378191451 100644
--- a/lib/std/crypto/25519/field.zig
+++ b/lib/std/crypto/25519/field.zig
@@ -292,7 +292,7 @@ pub const Fe = struct {
return _carry128(&r);
}
- fn _sq(a: Fe, double: bool) callconv(.Inline) Fe {
+ fn _sq(a: Fe, comptime double: bool) callconv(.Inline) Fe {
var ax: [5]u128 = undefined;
var r: [5]u128 = undefined;
comptime var i = 0;
diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig
index a775094c48..375cf0a3cb 100644
--- a/lib/std/crypto/poly1305.zig
+++ b/lib/std/crypto/poly1305.zig
@@ -39,7 +39,7 @@ pub const Poly1305 = struct {
};
}
- fn blocks(st: *Poly1305, m: []const u8, last: bool) void {
+ fn blocks(st: *Poly1305, m: []const u8, comptime last: bool) void {
const hibit: u64 = if (last) 0 else 1 << 40;
const r0 = st.r[0];
const r1 = st.r[1];
diff --git a/lib/std/os.zig b/lib/std/os.zig
index fbee2fdcbe..6c6baf49f3 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -1049,7 +1049,7 @@ pub const OpenError = error{
} || UnexpectedError;
/// Open and possibly create a file. Keeps trying if it gets interrupted.
-/// See also `openC`.
+/// See also `openZ`.
pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {
if (std.Target.current.os.tag == .windows) {
const file_path_w = try windows.sliceToPrefixedFileW(file_path);
@@ -1147,7 +1147,7 @@ pub fn openW(file_path_w: []const u16, flags: u32, perm: mode_t) OpenError!fd_t
/// Open and possibly create a file. Keeps trying if it gets interrupted.
/// `file_path` is relative to the open directory handle `dir_fd`.
-/// See also `openatC`.
+/// See also `openatZ`.
pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t {
if (builtin.os.tag == .wasi) {
@compileError("use openatWasi instead");
@@ -1754,7 +1754,7 @@ pub const UnlinkError = error{
} || UnexpectedError;
/// Delete a name and possibly the file it refers to.
-/// See also `unlinkC`.
+/// See also `unlinkZ`.
pub fn unlink(file_path: []const u8) UnlinkError!void {
if (builtin.os.tag == .wasi) {
@compileError("unlink is not supported in WASI; use unlinkat instead");
@@ -3419,7 +3419,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
}
}
-pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound };
+pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound, SymLinkLoop };
/// Similar to `fstat`, but returns stat of a resource pointed to by `pathname`
/// which is relative to `dirfd` handle.
@@ -3466,8 +3466,10 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
EBADF => unreachable, // Always a race condition.
ENOMEM => return error.SystemResources,
EACCES => return error.AccessDenied,
+ EPERM => return error.AccessDenied,
EFAULT => unreachable,
ENAMETOOLONG => return error.NameTooLong,
+ ELOOP => return error.SymLinkLoop,
ENOENT => return error.FileNotFound,
ENOTDIR => return error.FileNotFound,
else => |err| return unexpectedErrno(err),
diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig
index 70aa3c8dc6..c6185ef093 100644
--- a/lib/std/special/build_runner.zig
+++ b/lib/std/special/build_runner.zig
@@ -82,9 +82,9 @@ pub fn main() !void {
builder.verbose = true;
} else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
return usage(builder, false, stdout_stream);
- } else if (mem.eql(u8, arg, "--prefix")) {
+ } else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {
install_prefix = nextArg(args, &arg_idx) orelse {
- warn("Expected argument after --prefix\n\n", .{});
+ warn("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--search-prefix")) {
@@ -188,7 +188,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
\\General Options:
\\ -h, --help Print this help and exit
\\ --verbose Print commands before executing them
- \\ --prefix [path] Override default install prefix
+ \\ -p, --prefix [path] Override default install prefix
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
\\ --color [auto|off|on] Enable or disable colored error messages
\\