Fixes invalid memory access
std::string_view causes invalid memory access in multipart branch when
assigned local variable goes out of scope and string_view is passed to
ramAuthenticateUser. Moved MultipartParser to higher scope, to ensure
it is not deleted before std::string_view.
Tested:
- Executed post on /login, got response:
{
"data": "User 'root' logged in",
"message": "200 OK",
"status": "ok"
}
Change-Id: I0b02dddcb1a887d442525ffedb7a08a00087f2f2
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/include/login_routes.hpp b/include/login_routes.hpp
index fd1c357..0ff313c 100644
--- a/include/login_routes.hpp
+++ b/include/login_routes.hpp
@@ -24,6 +24,7 @@
.methods(boost::beast::http::verb::post)(
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ MultipartParser parser;
std::string_view contentType = req.getHeaderValue("content-type");
std::string_view username;
std::string_view password;
@@ -119,7 +120,6 @@
else if (contentType.starts_with("multipart/form-data"))
{
looksLikePhosphorRest = true;
- MultipartParser parser;
ParserError ec = parser.parse(req);
if (ec != ParserError::PARSER_SUCCESS)
{