ES: Make sure the TMD and ticket are valid before use

This commit is contained in:
Léo Lam 2017-02-14 13:15:02 +01:00
parent 5104caf6a6
commit 44a3db21e4
3 changed files with 12 additions and 7 deletions

View File

@ -186,7 +186,7 @@ u32 ES::OpenTitleContent(u32 CFD, u64 TitleID, u16 Index)
{ {
const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID);
if (!Loader.IsValid()) if (!Loader.IsValid() || !Loader.GetTicket().IsValid())
{ {
WARN_LOG(IOS_ES, "ES: loader not valid for %" PRIx64, TitleID); WARN_LOG(IOS_ES, "ES: loader not valid for %" PRIx64, TitleID);
return 0xffffffff; return 0xffffffff;
@ -501,11 +501,11 @@ IPCCommandResult ES::GetTitleContents(const IOCtlVRequest& request)
if (!rNANDContent.IsValid()) if (!rNANDContent.IsValid())
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
for (const auto& content : rNANDContent.GetContent()) for (const auto& content : rNANDContent.GetTMD().GetContents())
{ {
const u16 index = content.m_metadata.index; const u16 index = content.index;
Memory::Write_U32(content.m_metadata.id, request.io_vectors[0].address + index * 4); Memory::Write_U32(content.id, request.io_vectors[0].address + index * 4);
INFO_LOG(IOS_ES, "IOCTL_ES_GETTITLECONTENTS: Index %d: %08x", index, content.m_metadata.id); INFO_LOG(IOS_ES, "IOCTL_ES_GETTITLECONTENTS: Index %d: %08x", index, content.id);
} }
return GetDefaultReply(IPC_SUCCESS); return GetDefaultReply(IPC_SUCCESS);
@ -568,7 +568,7 @@ IPCCommandResult ES::ReadContent(const IOCtlVRequest& request)
{ {
const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(rContent.m_TitleID); const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(rContent.m_TitleID);
// ContentLoader should never be invalid; rContent has been created by it. // ContentLoader should never be invalid; rContent has been created by it.
if (ContentLoader.IsValid()) if (ContentLoader.IsValid() && ContentLoader.GetTicket().IsValid())
{ {
const DiscIO::SNANDContent* pContent = ContentLoader.GetContentByIndex(rContent.m_Index); const DiscIO::SNANDContent* pContent = ContentLoader.GetContentByIndex(rContent.m_Index);
if (!pContent->m_Data->GetRange(rContent.m_Position, Size, pDest)) if (!pContent->m_Data->GetRange(rContent.m_Position, Size, pDest))

View File

@ -156,6 +156,11 @@ CNANDContentLoader::~CNANDContentLoader()
{ {
} }
bool CNANDContentLoader::IsValid() const
{
return m_Valid && m_tmd.IsValid();
}
const SNANDContent* CNANDContentLoader::GetContentByIndex(int index) const const SNANDContent* CNANDContentLoader::GetContentByIndex(int index) const
{ {
for (auto& Content : m_Content) for (auto& Content : m_Content)

View File

@ -77,7 +77,7 @@ public:
explicit CNANDContentLoader(const std::string& content_name); explicit CNANDContentLoader(const std::string& content_name);
~CNANDContentLoader(); ~CNANDContentLoader();
bool IsValid() const { return m_Valid; } bool IsValid() const;
void RemoveTitle() const; void RemoveTitle() const;
const SNANDContent* GetContentByIndex(int index) const; const SNANDContent* GetContentByIndex(int index) const;
const IOS::ES::TMDReader& GetTMD() const { return m_tmd; } const IOS::ES::TMDReader& GetTMD() const { return m_tmd; }