diff --git a/src/libxrpl/protocol/STParsedJSON.cpp b/src/libxrpl/protocol/STParsedJSON.cpp index 3fb2825581..b928f0dbd8 100644 --- a/src/libxrpl/protocol/STParsedJSON.cpp +++ b/src/libxrpl/protocol/STParsedJSON.cpp @@ -78,7 +78,8 @@ static inline Json::Value not_an_object(std::string const& object, std::string const& field) { auto const fieldName = make_name(object, field); - return RPC::make_error(rpcINVALID_PARAMS, "Field '" + fieldName + "' is not a JSON object."); + std::string const msg = "Field '" + fieldName + "' is not a JSON object."; + return RPC::make_error(rpcINVALID_PARAMS, msg); } static inline Json::Value @@ -97,28 +98,32 @@ static inline Json::Value unknown_field(std::string const& object, std::string const& field) { auto const fieldName = make_name(object, field); - return RPC::make_error(rpcINVALID_PARAMS, "Field '" + fieldName + "' is unknown."); + std::string const msg = "Field '" + fieldName + "' is unknown."; + return RPC::make_error(rpcINVALID_PARAMS, msg); } static inline Json::Value out_of_range(std::string const& object, std::string const& field) { auto const fieldName = make_name(object, field); - return RPC::make_error(rpcINVALID_PARAMS, "Field '" + fieldName + "' is out of range."); + std::string const msg = "Field '" + fieldName + "' is out of range."; + return RPC::make_error(rpcINVALID_PARAMS, msg); } static inline Json::Value bad_type(std::string const& object, std::string const& field) { auto const fieldName = make_name(object, field); - return RPC::make_error(rpcINVALID_PARAMS, "Field '" + fieldName + "' has bad type."); + std::string const msg = "Field '" + fieldName + "' has bad type."; + return RPC::make_error(rpcINVALID_PARAMS, msg); } static inline Json::Value invalid_data(std::string const& object, std::string const& field) { auto const fieldName = make_name(object, field); - return RPC::make_error(rpcINVALID_PARAMS, "Field '" + fieldName + "' has invalid data."); + std::string const msg = "Field '" + fieldName + "' has invalid data."; + return RPC::make_error(rpcINVALID_PARAMS, msg); } static inline Json::Value @@ -131,14 +136,16 @@ static inline Json::Value array_expected(std::string const& object, std::string const& field) { auto const fieldName = make_name(object, field); - return RPC::make_error(rpcINVALID_PARAMS, "Field '" + fieldName + "' must be a JSON array."); + std::string const msg = "Field '" + fieldName + "' must be a JSON array."; + return RPC::make_error(rpcINVALID_PARAMS, msg); } static inline Json::Value string_expected(std::string const& object, std::string const& field) { auto const fieldName = make_name(object, field); - return RPC::make_error(rpcINVALID_PARAMS, "Field '" + fieldName + "' must be a string."); + std::string const msg = "Field '" + fieldName + "' must be a string."; + return RPC::make_error(rpcINVALID_PARAMS, msg); } static inline Json::Value diff --git a/src/xrpld/app/paths/detail/AMMLiquidity.cpp b/src/xrpld/app/paths/detail/AMMLiquidity.cpp index ebbb51ce25..97c4ea7c47 100644 --- a/src/xrpld/app/paths/detail/AMMLiquidity.cpp +++ b/src/xrpld/app/paths/detail/AMMLiquidity.cpp @@ -179,7 +179,10 @@ AMMLiquidity::getOffer(ReadView const& view, std::optional c } catch (std::overflow_error const& e) { - JLOG(j_.error()) << "AMMLiquidity::getOffer overflow " << e.what(); + // Store e.what() in a local variable to prevent stack-use-after-scope + // when the exception's internal storage becomes invalid in coroutine context + std::string const errorMsg = e.what(); + JLOG(j_.error()) << "AMMLiquidity::getOffer overflow " << errorMsg; if (!view.rules().enabled(fixAMMOverflowOffer)) return maxOffer(balances, view.rules()); else @@ -187,7 +190,10 @@ AMMLiquidity::getOffer(ReadView const& view, std::optional c } catch (std::exception const& e) { - JLOG(j_.error()) << "AMMLiquidity::getOffer exception " << e.what(); + // Store e.what() in a local variable to prevent stack-use-after-scope + // when the exception's internal storage becomes invalid in coroutine context + std::string const errorMsg = e.what(); + JLOG(j_.error()) << "AMMLiquidity::getOffer exception " << errorMsg; } return std::nullopt; }();