1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-23 10:52:13 +00:00

sf: handle serialization errors more accurately and gracefully

This commit is contained in:
Michael Scire 2020-08-11 16:40:57 -07:00
parent 44c5cb9789
commit 874208b44a

View file

@ -43,16 +43,19 @@ namespace ams::sf::cmif {
CmifOutHeader *out_header = nullptr;
Result command_result = cmd_handler(&out_header, ctx, in_message_raw_data);
/* Forward forwardable results, otherwise ensure we can send result to user. */
R_TRY_CATCH(command_result) {
R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged)
R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); }
} R_END_TRY_CATCH;
/* Forward any meta-context change result. */
if (sf::impl::ResultRequestContextChanged::Includes(command_result)) {
return command_result;
}
/* Otherwise, ensure that we're able to write the output header. */
if (out_header == nullptr) {
AMS_ABORT_UNLESS(R_FAILED(command_result));
return command_result;
}
/* Write output header to raw data. */
if (out_header != nullptr) {
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result.GetValue(), 0};
}
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result.GetValue(), 0};
return ResultSuccess();
}
@ -87,19 +90,24 @@ namespace ams::sf::cmif {
CmifOutHeader *out_header = nullptr;
Result command_result = cmd_handler(&out_header, ctx, in_message_raw_data);
/* Forward forwardable results, otherwise ensure we can send result to user. */
R_TRY_CATCH(command_result) {
R_CATCH(sm::mitm::ResultShouldForwardToSession) {
return ctx.session->ForwardRequest(ctx);
}
R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged)
R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); }
} R_END_TRY_CATCH;
/* If we should, forward the request to the forward session. */
if (sm::mitm::ResultShouldForwardToSession::Includes(command_result)) {
return ctx.session->ForwardRequest(ctx);
}
/* Forward any meta-context change result. */
if (sf::impl::ResultRequestContextChanged::Includes(command_result)) {
return command_result;
}
/* Otherwise, ensure that we're able to write the output header. */
if (out_header == nullptr) {
AMS_ABORT_UNLESS(R_FAILED(command_result));
return command_result;
}
/* Write output header to raw data. */
if (out_header != nullptr) {
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result.GetValue(), 0};
}
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result.GetValue(), 0};
return ResultSuccess();
}