From 1dafe18b42ddb520b63d78865ffb24c38c5115ea Mon Sep 17 00:00:00 2001 From: Vojtech Horky Date: Fri, 14 Jul 2023 16:24:56 +0200 Subject: [PATCH] C++ lib: prevent use after free (hackish) --- uspace/lib/cpp/src/future.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/uspace/lib/cpp/src/future.cpp b/uspace/lib/cpp/src/future.cpp index bb23ee2d5..0c1c62a00 100644 --- a/uspace/lib/cpp/src/future.cpp +++ b/uspace/lib/cpp/src/future.cpp @@ -83,6 +83,15 @@ namespace std const char* future_error::what() const noexcept { - return code().message().c_str(); + /* + * FIXME + * Following code would be optimal but the message string is + * actually destroyed before the function returns so we would + * be returning a dangling pointer. No simple fix available, hence + * we use the ugly hack. + */ + //return code().message().c_str(); +#define QUOTE_ARG(arg) #arg + return "future_error, see " __FILE__ ":" QUOTE_ARG(__LINE__); } } -- 2.11.4.GIT