]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Safely encapsulate fdopen within DBus::FileDescriptor to prevent leaks 1151/head
authorDevansh-567 <devansh.jay.singh@gmail.com>
Mon, 22 Jun 2026 09:14:39 +0000 (14:44 +0530)
committerDevansh-567 <devansh.jay.singh@gmail.com>
Mon, 22 Jun 2026 13:28:04 +0000 (18:58 +0530)
client/proxy/commands.cc
dbus/DBusPipe.cc
dbus/DBusPipe.h
server/FilesTransferTask.cc

index 4fbe863ec773bc44b31fe80813762130f07c5e7d..3279d3373d6c8c28bc055e4e3da5e975a832e36d 100644 (file)
@@ -554,7 +554,7 @@ command_get_xfiles_by_pipe(DBus::Connection& conn, const string& config_name, un
 
     vector<XFile> files;
 
-    FILE* fin = fdopen(fd.get_fd(), "r");
+    FILE* fin = fd.fdopen("r");
     if (!fin)
        SN_THROW(IOErrorException("reading pipe failed, fdopen failed: " + stringerror(errno)));
 
index 691975eb4bf4da08fe8ba8869b2b8a855096e5bb..74eb680f5e3b3f8494081bff0caa78431856e5b7 100644 (file)
@@ -65,6 +65,14 @@ namespace DBus
        return marshaller;
     }
 
+    FILE*
+    FileDescriptor::fdopen(const char* mode)
+    {
+        FILE* ret = ::fdopen(_fd, mode);
+        if (ret)
+            _fd = -1;
+        return ret;
+    }
 
     Pipe::Pipe()
     {
index 13a15a6124b7e84814abdf65944867994614a2f4..63bacf6aeb848041b6de2a0612bfff20e227cc77 100644 (file)
@@ -44,6 +44,8 @@ namespace DBus
        int get_fd() const { return _fd; }
        void set_fd(int fd) { _fd = fd; }
 
+       FILE* fdopen(const char* mode);
+
     private:
 
        int _fd = -1;
index b708e23d8ac86cecaa25d38181ae3f50162a91e8..a0f3d66b1f400ddaaae83ff18bb2d81866037037 100644 (file)
@@ -33,7 +33,7 @@ FilesTransferTask::FilesTransferTask(const Files& files)
 void
 FilesTransferTask::run()
 {
-    FILE* fout = fdopen(get_write_end().get_fd(), "w");
+    FILE* fout = get_write_end().fdopen("w");
     if (!fout)
        SN_THROW(StreamException());