Clean-up: coverity warns of uncaught exception during logging
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 6 Jan 2023 17:01:53 +0000 (12:01 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 9 Jan 2023 19:13:13 +0000 (14:13 -0500)
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 <jeremie.galarneau@efficios.com>
Change-Id: Ia70505517678ae182f6479feeb264c9402aa1381

src/common/file-descriptor.hpp
src/common/uuid.cpp

index 6354a12e2f96f5007ab67cd6cf4d98c004f546f9..9bda86731b500d77a136f5e0ac69877e5f7af296 100644 (file)
@@ -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 */
index bef038ac6f6675b915a9b3ee816b736918614190..4a1038b330caf66e4be141bc251e5dcd14b965b6 100644 (file)
@@ -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;
                }
This page took 0.027452 seconds and 4 git commands to generate.