authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-08 17:52:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-08 17:52:28-04:00
log1d2fc446bd1cf90fb93a1164538dcc4530a06d33
treece0358206c00d93bf1524eefab28a6045c679ec6
parentfc9e28ea37e0110836d6958c39ffe78ea6cad0f3
signaturelock-open Commit is signed but in an unrecognized format.

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

1 files changed, 14 insertions(+), 4 deletions(-)

std/os/linux.zig+14-4
......@@ -106,12 +106,22 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
106106 return syscall2(SYS_getcwd, @ptrToInt(buf), size);
107107}
108108
109pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
110 return syscall3(SYS_getdents, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count);
109pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
110 return syscall3(
111 SYS_getdents,
112 @bitCast(usize, isize(fd)),
113 @ptrToInt(dirp),
114 std.math.min(len, maxInt(c_int)),
115 );
111116}
112117
113pub fn getdents64(fd: i32, dirp: [*]u8, count: usize) usize {
114 return syscall3(SYS_getdents64, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count);
118pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
119 return syscall3(
120 SYS_getdents64,
121 @bitCast(usize, isize(fd)),
122 @ptrToInt(dirp),
123 std.math.min(len, maxInt(c_int)),
124 );
115125}
116126
117127pub fn inotify_init1(flags: u32) usize {