Skip to content

Commit 2b3088b

Browse files
AustinWiseam11
andauthored
Fix size of dirent buffer on illumos (#104448)
--------- Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
1 parent 773f3cd commit 2b3088b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/native/libs/System.Native/pal_io.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#endif
5555
#endif
5656

57+
#ifdef TARGET_SUNOS
58+
#include <sys/param.h>
59+
#endif
60+
5761
#ifdef _AIX
5862
#include <alloca.h>
5963
// Somehow, AIX mangles the definition for this behind a C++ def
@@ -436,10 +440,17 @@ static const size_t dirent_alignment = 8;
436440
int32_t SystemNative_GetReadDirRBufferSize(void)
437441
{
438442
#if HAVE_READDIR_R
443+
size_t result = sizeof(struct dirent);
444+
#ifdef TARGET_SUNOS
445+
// The d_name array is declared with only a single byte in it.
446+
// We have to add pathconf("dir", _PC_NAME_MAX) more bytes.
447+
// MAXNAMELEN is the largest possible value returned from pathconf.
448+
result += MAXNAMELEN;
449+
#endif
439450
// dirent should be under 2k in size
440-
assert(sizeof(struct dirent) < 2048);
451+
assert(result < 2048);
441452
// add some extra space so we can align the buffer to dirent.
442-
return sizeof(struct dirent) + dirent_alignment - 1;
453+
return (int32_t)(result + dirent_alignment - 1);
443454
#else
444455
return 0;
445456
#endif

0 commit comments

Comments
 (0)