Skip to content

Commit

Permalink
handle sysconf(SC_OPEN_MAX) returning > INT_MAX;
Browse files Browse the repository at this point in the history
bz3581; ok dtucker
  • Loading branch information
djmdjm committed Jun 22, 2023
1 parent c1c2ca1 commit cfca6f1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions ssh-keyscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,21 @@ fdlim_get(int hard)
{
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
struct rlimit rlfd;
rlim_t lim;

if (getrlimit(RLIMIT_NOFILE, &rlfd) == -1 ||
(hard ? rlfd.rlim_max : rlfd.rlim_cur) < 0)
if (getrlimit(RLIMIT_NOFILE, &rlfd) == -1)
return -1;
lim = hard ? rlfd.rlim_max : rlfd.rlim_cur;
if (lim <= 0)
return -1;
if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY ||
(hard ? rlfd.rlim_max : rlfd.rlim_cur) > INT_MAX)
return SSH_SYSFDMAX;
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
return SSH_SYSFDMAX;
return (SSH_SYSFDMAX <= 0) ? -1 :
((SSH_SYSFDMAX >= INT_MAX) ? INT_MAX : SSH_SYSFDMAX);
#endif
}

Expand Down

0 comments on commit cfca6f1

Please sign in to comment.