Skip to content

Commit

Permalink
Fix size of dirent buffer on illumos (#104448)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Adeel Mujahid <[email protected]>
  • Loading branch information
AustinWise and am11 authored Jul 16, 2024
1 parent 773f3cd commit 2b3088b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/native/libs/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#endif
#endif

#ifdef TARGET_SUNOS
#include <sys/param.h>
#endif

#ifdef _AIX
#include <alloca.h>
// Somehow, AIX mangles the definition for this behind a C++ def
Expand Down Expand Up @@ -436,10 +440,17 @@ static const size_t dirent_alignment = 8;
int32_t SystemNative_GetReadDirRBufferSize(void)
{
#if HAVE_READDIR_R
size_t result = sizeof(struct dirent);
#ifdef TARGET_SUNOS
// The d_name array is declared with only a single byte in it.
// We have to add pathconf("dir", _PC_NAME_MAX) more bytes.
// MAXNAMELEN is the largest possible value returned from pathconf.
result += MAXNAMELEN;
#endif
// dirent should be under 2k in size
assert(sizeof(struct dirent) < 2048);
assert(result < 2048);
// add some extra space so we can align the buffer to dirent.
return sizeof(struct dirent) + dirent_alignment - 1;
return (int32_t)(result + dirent_alignment - 1);
#else
return 0;
#endif
Expand Down

0 comments on commit 2b3088b

Please sign in to comment.