forked from Kistler-Group/sdbus-cpp
Avoid propagating msg unpack exceptions to event loop
This change addresses conditions where an exception is thrown by the library upon receipt of a malformed message from an external source, and propagated up to the event loop with no chance of interception by the application. This issue is only experienced by proxy convenience APIs, as low-level APIs allow the application to unpack the message. Strategy: 1. For malformed signals received by proxies: ignore the signal. 2. For malformed async method responses, translate the unpack exception into an sdbus::Error, and pass it to the caller as expected.
This commit is contained in:
committed by
Stanislav Angelovič
parent
e16ffb1288
commit
022831b8c3
@ -588,7 +588,20 @@ namespace sdbus {
|
||||
|
||||
// Deserialize input arguments from the message into the tuple (if no error occurred).
|
||||
if (error == nullptr)
|
||||
reply >> args;
|
||||
{
|
||||
try
|
||||
{
|
||||
reply >> args;
|
||||
}
|
||||
catch (const sdbus::Error& e)
|
||||
{
|
||||
// Catch message unpack exceptions and pass them to the callback
|
||||
// in the expected manner to avoid propagating them up the call
|
||||
// stack to the event loop.
|
||||
sdbus::apply(callback, &e, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke callback with input arguments from the tuple.
|
||||
sdbus::apply(callback, error, args);
|
||||
@ -628,7 +641,17 @@ namespace sdbus {
|
||||
tuple_of_function_input_arg_types_t<_Function> signalArgs;
|
||||
|
||||
// Deserialize input arguments from the signal message into the tuple
|
||||
signal >> signalArgs;
|
||||
try
|
||||
{
|
||||
signal >> signalArgs;
|
||||
}
|
||||
catch (const sdbus::Error& e)
|
||||
{
|
||||
// The convenience API callback cannot handle an incoming signal with
|
||||
// an unexpected payload, so catch and ignore this exception to avoid
|
||||
// propagating it up the call stack to the event loop.
|
||||
return;
|
||||
}
|
||||
|
||||
// Invoke callback with input arguments from the tuple.
|
||||
sdbus::apply(callback, signalArgs);
|
||||
|
Reference in New Issue
Block a user