From c4eef179909147cec0c6ac3e2fa9989b24065fc0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 5 Mar 2025 00:05:31 +0900 Subject: [PATCH] dirent-util: add several assertions in posix_getdents() Follow-up for e86a492ff08526e5adf85fa881c76f80adc3c84a. --- src/basic/dirent-util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/basic/dirent-util.h b/src/basic/dirent-util.h index 816b28e04f..f3007b6bc3 100644 --- a/src/basic/dirent-util.h +++ b/src/basic/dirent-util.h @@ -34,6 +34,13 @@ struct dirent *readdir_no_dot(DIR *dirp); * Let's introduce a simple wrapper. */ #if !HAVE_POSIX_GETDENTS static inline ssize_t posix_getdents(int fd, void *buf, size_t nbyte, int flags) { + assert(fd >= 0); + assert(buf); + assert(nbyte > 0); + + if (flags != 0) + return -EINVAL; /* Currently flags must be zero. */ + return getdents64(fd, buf, nbyte); } #endif