]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib:util: Move open() of /dev/null into the if-clause
authorAndreas Schneider <asn@samba.org>
Mon, 8 Jul 2024 08:14:39 +0000 (10:14 +0200)
committerGünther Deschner <gd@samba.org>
Tue, 16 Jul 2024 11:41:33 +0000 (11:41 +0000)
"Error: RESOURCE_LEAK (CWE-772):
samba-4.20.0rc2/lib/util/close_low_fd.c:40: open_fn: Returning handle opened by ""open"". [Note: The source code implementation of the function has been overridden by a user model.]
samba-4.20.0rc2/lib/util/close_low_fd.c:40: var_assign: Assigning: ""dev_null"" = handle returned from ""open(""/dev/null"", 2, 0)"".
samba-4.20.0rc2/lib/util/close_low_fd.c:52: overwrite_var: Overwriting handle ""dev_null"" in ""dev_null = open(""/dev/null"", 2, 0)"" leaks the handle.
   50|    }
   51|
   52|->  dev_null = open(""/dev/null"", O_RDWR, 0);
   53|    if (dev_null == -1) {
   54|    dev_null = open(""/dev/null"", O_WRONLY, 0);"

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
lib/util/close_low_fd.c

index 84a690676443e0df5094eb6eff3a54cc3e0c152d..5d52f617bbbefb0e733e61d3f8f4d26d76246a65 100644 (file)
@@ -47,9 +47,10 @@ _PUBLIC_ int close_low_fd(int fd)
                if (ret != 0) {
                        return errno;
                }
+
+               dev_null = open("/dev/null", O_RDWR, 0);
        }
 
-       dev_null = open("/dev/null", O_RDWR, 0);
        if (dev_null == -1) {
                dev_null = open("/dev/null", O_WRONLY, 0);
        }