closefrom: Handle lowfd < 0 properly

More important if close_range() is going to be used, since casting
negative values to 'unsigned int' might hide the errors.

[guillem@hadrons.org: Minor coding style fix. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
This commit is contained in:
cptpcrd 2021-02-07 14:22:21 -05:00 committed by Guillem Jover
parent a1f79978e8
commit c4fca5bb4f

View File

@ -179,6 +179,9 @@ closefrom_procfs(int lowfd)
void
closefrom(int lowfd)
{
if (lowfd < 0)
lowfd = 0;
/* Try the fast method first, if possible. */
#if defined(HAVE_FCNTL_CLOSEM)
if (fcntl(lowfd, F_CLOSEM, 0) != -1)