From c7f8bc55826bd0700e44be1886212aa3aefe7da2 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Fri, 24 Mar 2023 16:50:48 +0200 Subject: [PATCH] file_util: Check fd before using dup --- src/common/file_util.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 27ecef10d..5155b19a4 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -1187,6 +1187,8 @@ void OpenFStream( boost_iostreams& fstream, const std::string& filename) { IOFile file(filename, "r"); + if (file.GetFd() == -1) + return; int fd = dup(file.GetFd()); if (fd == -1) return; @@ -1199,6 +1201,8 @@ template <> void OpenFStream( boost_iostreams& fstream, const std::string& filename) { IOFile file(filename, "w"); + if (file.GetFd() == -1) + return; int fd = dup(file.GetFd()); if (fd == -1) return;