handle sysconf(SC_OPEN_MAX) returning > INT_MAX;

bz3581; ok dtucker
This commit is contained in:
Damien Miller 2023-06-22 15:04:03 +10:00
parent c1c2ca1365
commit cfca6f17e6
No known key found for this signature in database
1 changed files with 12 additions and 7 deletions

View File

@ -132,16 +132,21 @@ fdlim_get(int hard)
{ {
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE) #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
struct rlimit rlfd; struct rlimit rlfd;
rlim_t lim;
if (getrlimit(RLIMIT_NOFILE, &rlfd) == -1 || if (getrlimit(RLIMIT_NOFILE, &rlfd) == -1)
(hard ? rlfd.rlim_max : rlfd.rlim_cur) < 0)
return -1; return -1;
if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY || lim = hard ? rlfd.rlim_max : rlfd.rlim_cur;
(hard ? rlfd.rlim_max : rlfd.rlim_cur) > INT_MAX) if (lim <= 0)
return SSH_SYSFDMAX; return -1;
return hard ? rlfd.rlim_max : rlfd.rlim_cur; if (lim == RLIM_INFINITY)
lim = SSH_SYSFDMAX;
if (lim >= INT_MAX)
lim = INT_MAX;
return lim;
#else #else
return SSH_SYSFDMAX; return (SSH_SYSFDMAX <= 0) ? -1 :
((SSH_SYSFDMAX >= INT_MAX) ? INT_MAX : SSH_SYSFDMAX);
#endif #endif
} }