From: cptpcrd Date: Sun, 7 Feb 2021 19:22:21 +0000 (-0500) Subject: closefrom: Handle lowfd < 0 properly X-Git-Tag: 0.11.2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4fca5bb4fcf8509cb93db6e20314f22994c093b;p=thirdparty%2Flibbsd.git 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 --- diff --git a/src/closefrom.c b/src/closefrom.c index be38813..e2e10a8 100644 --- a/src/closefrom.c +++ b/src/closefrom.c @@ -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)