The branch, master has been updated
       via  206dcf7d426 lib:util: File descriptor being closed repeatedly.
      from  8441c03ccf8 lib:ldb: Print a debug message in case we have a 
corrupted MDB

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 206dcf7d426e9e85c896c54839008e194d9a2824
Author: baixiangcpp <baixiang...@gmail.com>
Date:   Fri Feb 10 11:01:47 2023 +0800

    lib:util: File descriptor being closed repeatedly.
    
    In file_load()/file_lines_load(), the file's fd is obtained using
    open(), and in fd_load() the fd is converted to a FILE* using
    fdopen(). However, after fclose(), the fd is closed again using
    close().
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15311
    Signed-off-by: baixiangcpp baixiang...@gmail.com
    Reviewed-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>
    
    Autobuild-User(master): Volker Lendecke <v...@samba.org>
    Autobuild-Date(master): Thu Feb 16 12:13:05 UTC 2023 on atb-devel-224

-----------------------------------------------------------------------

Summary of changes:
 lib/util/util_file.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/util_file.c b/lib/util/util_file.c
index af90e4a7621..fa5abadedec 100644
--- a/lib/util/util_file.c
+++ b/lib/util/util_file.c
@@ -175,13 +175,20 @@ _PUBLIC_ char *fd_load(int fd, size_t *psize, size_t 
maxsize, TALLOC_CTX *mem_ct
        size_t size = 0;
        size_t chunk = 1024;
        int err;
+       int fd_dup;
 
        if (maxsize == 0) {
                maxsize = SIZE_MAX;
        }
 
-       file = fdopen(fd, "r");
+       fd_dup = dup(fd);
+       if (fd_dup == -1) {
+               return NULL;
+       }
+
+       file = fdopen(fd_dup, "r");
        if (file == NULL) {
+               close(fd_dup);
                return NULL;
        }
 


-- 
Samba Shared Repository

Reply via email to