From a620bd7935c4b2dc94e472e62bd9a5c9434ea7b7 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 27 Jun 2019 15:08:40 +0200 Subject: Linux: Adjust gedents64 buffer size to int range [BZ #24740] The kernel interface uses type unsigned int, but there is an internal conversion to int, so INT_MAX is the correct limit. Part of the buffer will always be unused, but this is not a problem. Such huge buffers do not occur in practice anyway. Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/getdents64.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sysdeps/unix/sysv/linux/getdents64.c') diff --git a/sysdeps/unix/sysv/linux/getdents64.c b/sysdeps/unix/sysv/linux/getdents64.c index a6dd22106d..5e3ef9994e 100644 --- a/sysdeps/unix/sysv/linux/getdents64.c +++ b/sysdeps/unix/sysv/linux/getdents64.c @@ -19,11 +19,16 @@ #include #include #include +#include /* The kernel struct linux_dirent64 matches the 'struct dirent64' type. */ ssize_t __getdents64 (int fd, void *buf, size_t nbytes) { + /* The system call takes an unsigned int argument, and some length + checks in the kernel use an int type. */ + if (nbytes > INT_MAX) + nbytes = INT_MAX; return INLINE_SYSCALL_CALL (getdents64, fd, buf, nbytes); } libc_hidden_def (__getdents64) -- cgit 1.4.1