upstream: handle rlimits > INT_MAX (rlim_t is u64); ok dtucker

bz3581

OpenBSD-Commit-ID: 31cf59c041becc0e5ccb0a77106f812c4cd1cd74
This commit is contained in:
djm@openbsd.org 2023-06-21 05:06:04 +00:00 committed by Damien Miller
parent 8d33f2aa6b
commit a69062f169
No known key found for this signature in database
1 changed files with 8 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssh-keyscan.c,v 1.152 2023/03/31 04:21:56 djm Exp $ */
/* $OpenBSD: ssh-keyscan.c,v 1.153 2023/06/21 05:06:04 djm Exp $ */
/*
* Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
*
@ -23,6 +23,7 @@
#include <openssl/bn.h>
#endif
#include <limits.h>
#include <netdb.h>
#include <errno.h>
#ifdef HAVE_POLL_H
@ -132,11 +133,12 @@ fdlim_get(int hard)
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
struct rlimit rlfd;
if (getrlimit(RLIMIT_NOFILE, &rlfd) == -1)
return (-1);
if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY)
if (getrlimit(RLIMIT_NOFILE, &rlfd) == -1 ||
(hard ? rlfd.rlim_max : rlfd.rlim_cur) < 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;
else
return hard ? rlfd.rlim_max : rlfd.rlim_cur;
#else
return SSH_SYSFDMAX;