]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dirent-util: add several assertions in posix_getdents()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 4 Mar 2025 15:05:31 +0000 (00:05 +0900)
committerLennart Poettering <lennart@poettering.net>
Tue, 4 Mar 2025 21:54:01 +0000 (22:54 +0100)
Follow-up for e86a492ff08526e5adf85fa881c76f80adc3c84a.

src/basic/dirent-util.h

index 816b28e04feeda68d4373c955983d4dd8be0f887..f3007b6bc306244dbac3aa455a0671f960daa482 100644 (file)
@@ -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