zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 1d2fc446bd1cf90fb93a1164538dcc4530a06d33 (tree)
parent fc9e28ea37e0110836d6958c39ffe78ea6cad0f3
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon,  8 Jul 2019 17:52:28 -0400

cap getdents length argument to INT_MAX

the linux syscall treats this argument as having type int, so passing
extremely long buffer sizes would be misinterpreted by the kernel.
since "short reads" are always acceptable, just cap it down.

patch based on musl commit 3d178a7e2b75066593fbd5705742c5808395d90d

Diffstat:
Mstd/os/linux.zig | 18++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/std/os/linux.zig b/std/os/linux.zig @@ -106,12 +106,22 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { return syscall2(SYS_getcwd, @ptrToInt(buf), size); } -pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { - return syscall3(SYS_getdents, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count); +pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { + return syscall3( + SYS_getdents, + @bitCast(usize, isize(fd)), + @ptrToInt(dirp), + std.math.min(len, maxInt(c_int)), + ); } -pub fn getdents64(fd: i32, dirp: [*]u8, count: usize) usize { - return syscall3(SYS_getdents64, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count); +pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { + return syscall3( + SYS_getdents64, + @bitCast(usize, isize(fd)), + @ptrToInt(dirp), + std.math.min(len, maxInt(c_int)), + ); } pub fn inotify_init1(flags: u32) usize {