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; CmifOutHeader *out_header = nullptr;
Result command_result = cmd_handler(&out_header, ctx, in_message_raw_data); Result command_result = cmd_handler(&out_header, ctx, in_message_raw_data);
/* Forward forwardable results, otherwise ensure we can send result to user. */ /* Forward any meta-context change result. */
R_TRY_CATCH(command_result) { if (sf::impl::ResultRequestContextChanged::Includes(command_result)) {
R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged) return command_result;
R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); } }
} R_END_TRY_CATCH;
/* 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. */ /* 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(); return ResultSuccess();
} }
@ -87,19 +90,24 @@ namespace ams::sf::cmif {
CmifOutHeader *out_header = nullptr; CmifOutHeader *out_header = nullptr;
Result command_result = cmd_handler(&out_header, ctx, in_message_raw_data); Result command_result = cmd_handler(&out_header, ctx, in_message_raw_data);
/* Forward forwardable results, otherwise ensure we can send result to user. */ /* If we should, forward the request to the forward session. */
R_TRY_CATCH(command_result) { if (sm::mitm::ResultShouldForwardToSession::Includes(command_result)) {
R_CATCH(sm::mitm::ResultShouldForwardToSession) { return ctx.session->ForwardRequest(ctx);
return ctx.session->ForwardRequest(ctx); }
}
R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged) /* Forward any meta-context change result. */
R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); } if (sf::impl::ResultRequestContextChanged::Includes(command_result)) {
} R_END_TRY_CATCH; 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. */ /* 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(); return ResultSuccess();
} }