From 88277a52069ed0135254ce29da617ebb6ecddbb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 6 Jan 2023 12:01:53 -0500 Subject: [PATCH] Clean-up: coverity warns of uncaught exception during logging MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Coverity reports: 1502349 Uncaught exception If the exception is ever thrown, the program will crash. In lttng::​file_descriptor::​~file_descriptor(): A C++ exception is thrown but never caught (CWE-248) and 1502348 Uncaught exception If the exception is ever thrown, the program will crash. In main: A C++ exception is thrown but never caught (CWE-248) Both have the same cause: libfmt should not be used in "final" catch blocks before returning to non exception-safe code in order to contain all exceptions. As we add custom formaters, it could be interesting to revisit this and provide a noexcept wrapper for fmt::format. For the moment not much is lost (beyond format string type safety) from using the existing logging macros directly. Signed-off-by: Jérémie Galarneau Change-Id: Ia70505517678ae182f6479feeb264c9402aa1381 --- src/common/file-descriptor.hpp | 7 ++----- src/common/uuid.cpp | 6 ++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/common/file-descriptor.hpp b/src/common/file-descriptor.hpp index 6354a12e2..9bda86731 100644 --- a/src/common/file-descriptor.hpp +++ b/src/common/file-descriptor.hpp @@ -41,10 +41,7 @@ public: const auto ret = ::close(_raw_fd); if (ret) { - PERROR("%s", - fmt::format("Failed to close file descriptor: fd = {}", - _raw_fd) - .c_str()); + PERROR("Failed to close file descriptor: fd=%i", _raw_fd); } } @@ -63,4 +60,4 @@ private: int _raw_fd; }; -} /* namespace lttng */ \ No newline at end of file +} /* namespace lttng */ diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp index bef038ac6..4a1038b33 100644 --- a/src/common/uuid.cpp +++ b/src/common/uuid.cpp @@ -85,10 +85,8 @@ int lttng_uuid_generate(lttng_uuid& uuid_out) try { srand(lttng::random::produce_best_effort_random_seed()); } catch (std::exception& e) { - ERR("%s", - fmt::format("Failed to initialize random seed during generation of UUID: {}", - e.what()) - .c_str()); + ERR("Failed to initialize random seed during generation of UUID: %s", + e.what()); ret = -1; goto end; } -- 2.34.1