[openssh-commits] [openssh] 01/01: handle sysconf(SC_OPEN_MAX) returning > INT_MAX;

git+noreply at mindrot.org git+noreply at mindrot.org
Thu Jun 22 15:05:04 AEST 2023


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit cfca6f17e64baed6822bb927ed9f372ce64d9c5b
Author: Damien Miller <djm at mindrot.org>
Date:   Thu Jun 22 15:04:03 2023 +1000

    handle sysconf(SC_OPEN_MAX) returning > INT_MAX;
    
    bz3581; ok dtucker
---
 ssh-keyscan.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index 96c6e906..1d2df709 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -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;
-	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;
+	lim = hard ? rlfd.rlim_max : rlfd.rlim_cur;
+	if (lim <= 0)
+		return -1;
+	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
 }
 

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list