From a69062f1695ac9c3c3dea29d3044c72aaa6af0ea Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Wed, 21 Jun 2023 05:06:04 +0000 Subject: [PATCH] upstream: handle rlimits > INT_MAX (rlim_t is u64); ok dtucker bz3581 OpenBSD-Commit-ID: 31cf59c041becc0e5ccb0a77106f812c4cd1cd74 --- ssh-keyscan.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ssh-keyscan.c b/ssh-keyscan.c index a53188c7b..96c6e9066 100644 --- a/ssh-keyscan.c +++ b/ssh-keyscan.c @@ -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 . * @@ -23,6 +23,7 @@ #include #endif +#include #include #include #ifdef HAVE_POLL_H @@ -132,12 +133,13 @@ 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; + return hard ? rlfd.rlim_max : rlfd.rlim_cur; #else return SSH_SYSFDMAX; #endif