diff --git a/lib/libc/sys/closefrom.c b/lib/libc/sys/closefrom.c index ceab46872d07..8ff2f9e96e4a 100644 --- a/lib/libc/sys/closefrom.c +++ b/lib/libc/sys/closefrom.c @@ -28,6 +28,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include @@ -40,7 +41,7 @@ closefrom(int lowfd) { if (__getosreldate() >= CLOSE_RANGE_OSREL) - __sys_close_range(lowfd, ~0U, 0); + __sys_close_range(MAX(0, lowfd), ~0U, 0); else /* Fallback to closefrom(2) on older kernels. */ syscall(SYS_freebsd12_closefrom, lowfd);