]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
closefrom: Handle lowfd < 0 properly
authorcptpcrd <cptpcrd.git@gmail.com>
Sun, 7 Feb 2021 19:22:21 +0000 (14:22 -0500)
committerGuillem Jover <guillem@hadrons.org>
Mon, 8 Feb 2021 03:02:46 +0000 (04:02 +0100)
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>
src/closefrom.c

index be38813a1984a6e7f8c84f817c01564552a8e0ed..e2e10a888765847f812c6ecd06ef7e40367906c9 100644 (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)