Skip to content

Commit d9e9fe9

Browse files
committed
fs: _kern_read_dir, limit entries and correct reclen calculation
1 parent a5db588 commit d9e9fe9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/system/libroot2/fs/fs.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ _kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize, uint32 maxCount
534534

535535
int i = 0;
536536
size_t pos = 0;
537+
uint32 maxEntriesInBuffer = bufferSize / sizeof(dirent);
538+
if (maxCount > maxEntriesInBuffer)
539+
maxCount = maxEntriesInBuffer;
540+
537541
while (pos < (size_t)ret && i < (int)maxCount) {
538542
if ((size_t)ret - pos < LINUX_DIRENT64_HEADER)
539543
break;
@@ -550,7 +554,7 @@ _kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize, uint32 maxCount
550554

551555
buffer[i].d_ino = (ino_t)d_ino;
552556
buffer[i].d_off = (off_t)d_off;
553-
buffer[i].d_reclen = reclen;
557+
buffer[i].d_reclen = sizeof(dirent);
554558

555559
size_t name_len = reclen - LINUX_DIRENT64_HEADER;
556560
size_t dst_size = sizeof(buffer[i].d_name);

0 commit comments

Comments
 (0)