From 8ad133dbc0ca0ea726aa6aa87ffb5a05ab37ebca Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 9 Aug 2024 12:32:39 +1000 Subject: [PATCH] FileSystem: Fix crash on file open fail in WriteAtomicRenamedFile() --- src/common/file_system.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 61ed81b49..79613628e 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -1235,6 +1235,9 @@ bool FileSystem::WriteAtomicRenamedFile(std::string filename, const void* data, Error* error /*= nullptr*/) { AtomicRenamedFile fp = CreateAtomicRenamedFile(std::move(filename), "wb", error); + if (!fp) + return false; + if (data_length > 0 && std::fwrite(data, 1u, data_length, fp.get()) != data_length) [[unlikely]] { Error::SetErrno(error, "fwrite() failed: ", errno);