Skip to content

Commit b3629c9

Browse files
committed
MB-28630: Try to catch std::bad_function_call during privilege check
The std::bad_function_call is thrown when a std::function is called but no function is specified (whithout any sensible context for us to locate where it comes from). My gut feeling tells me this is because the system is in a hosed state (most likely cookie corruption), but in order to try to locate where it is being thrown we need to start narrowing the places to look. Change-Id: I8fdbab0f0baf0eeecf38e910b70153624de15ef2 Reviewed-on: http://review.couchbase.org/90844 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 0cfd95d commit b3629c9

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

daemon/mcbp_privileges.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@
2121

2222
using namespace cb::rbac;
2323

24+
PrivilegeAccess McbpPrivilegeChains::invoke(protocol_binary_command command,
25+
Cookie& cookie) {
26+
auto& chain = commandChains[command];
27+
if (chain.empty()) {
28+
return cb::rbac::PrivilegeAccess::Fail;
29+
} else {
30+
try {
31+
return chain.invoke(cookie);
32+
} catch (const std::bad_function_call&) {
33+
LOG_WARNING(
34+
"{}: bad_function_call caught while evaluating access "
35+
"control for opcode: {:x}",
36+
cookie.getConnection().getId(),
37+
command);
38+
// Let the connection catch the exception and shut down the
39+
// connection
40+
throw;
41+
}
42+
}
43+
}
44+
2445
template <Privilege T>
2546
static PrivilegeAccess require(Cookie& cookie) {
2647
return cookie.getConnection().checkPrivilege(T, cookie);

daemon/mcbp_privileges.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ class McbpPrivilegeChains {
4848
* Stale - the authentication context is out of date
4949
*/
5050
cb::rbac::PrivilegeAccess invoke(protocol_binary_command command,
51-
Cookie& cookie) {
52-
auto& chain = commandChains[command];
53-
if (chain.empty()) {
54-
return cb::rbac::PrivilegeAccess::Fail;
55-
} else {
56-
return chain.invoke(cookie);
57-
}
58-
}
51+
Cookie& cookie);
5952

6053
protected:
6154
/*

0 commit comments

Comments
 (0)