Fix coredump on async method during validatePrivilege
PATCH may cause bmcweb to coredump depending on timing
of `validatePrivilege` execution. It is because `req' is captured as
reference, and it may be cleared-up before async-call method completes.
(This problem can be seen more frequently by enabling debug mode).
This commit is to keep `req` during to async-method execution.
Tested:
- Create a ReadOnly user - here, called as `readonly`
- Using `redfishtool`, run PATCH on `readonly` user role.
```
$ redfishtool -vvvvv raw -r ${bmc}:18080 -u ${user} -p ${password} -S Always PATCH /redfish/v1/AccountService/Accounts/readonly --data='{"RoleId":"Administrator"}'
...
This sometimes fails because bmcweb coredump
```
After:
```
$ redfishtool raw -r ${bmc}:18080 -u ${user} -p ${password} -S Always PATCH /redfish/v1/AccountService/Accounts/readonly --data='{"RoleId":"Administrator"}'
{
"@odata.id": "/redfish/v1/AccountService/Accounts/readonly",
"@odata.type": "#ManagerAccount.v1_7_0.ManagerAccount",
...
}
```
Change-Id: I2a28d1743cfc0fbd9239f69dec5584b34c7ebe43
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/include/dbus_privileges.hpp b/include/dbus_privileges.hpp
index 6602a5c..b2bb1e3 100644
--- a/include/dbus_privileges.hpp
+++ b/include/dbus_privileges.hpp
@@ -150,7 +150,8 @@
}
std::string username = req.session->username;
crow::connections::systemBus->async_method_call(
- [&req, asyncResp, &rule, callback(std::forward<CallbackFn>(callback))](
+ [req{std::move(req)}, asyncResp, &rule,
+ callback(std::forward<CallbackFn>(callback))](
const boost::system::error_code& ec,
const dbus::utility::DBusPropertiesMap& userInfoMap) mutable {
afterGetUserInfo(req, asyncResp, rule,