cellSaveData: Add some listSet error checks

* Check listSet->fixedListNum.
* Check listSet->fixedList for nullptr and its directory items names.
* Check listSet->focusDirName for nullptr and directory name.
* Check listSet->newData->iconPosition.
* Check listSet->newData->dirName for nullptr and directory string.
* Check statSet->setParam->parental_level for old sdk.
* Return an error if listSet->focusPosition is NEWDATA and listSet->newData is nullptr.
* Simplify savedata directory list selection.
This commit is contained in:
Eladash 2020-03-13 15:01:37 +02:00 committed by Ivan
parent 54af8ec544
commit d58f52ff31

View file

@ -701,27 +701,134 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
return display_callback_result_error_message(ppu, *result, errDialog); return display_callback_result_error_message(ppu, *result, errDialog);
} }
// Clean save data list if (listSet->fixedListNum > CELL_SAVEDATA_LISTITEM_MAX)
save_entries.erase(std::remove_if(save_entries.begin(), save_entries.end(), [&listSet](const SaveDataEntry& entry) -> bool
{ {
// ****** sysutil savedata parameter error : 38 ******
return {CELL_SAVEDATA_ERROR_PARAM, "38"};
}
if (listSet->fixedListNum && !listSet->fixedList)
{
// ****** sysutil savedata parameter error : 39 ******
return {CELL_SAVEDATA_ERROR_PARAM, "39"};
}
else
{
// TODO: What happens if fixedListNum is zero?
}
std::set<std::string_view> selected_list;
for (u32 i = 0; i < listSet->fixedListNum; i++) for (u32 i = 0; i < listSet->fixedListNum; i++)
{ {
if (entry.dirName == listSet->fixedList[i].dirName) switch (sysutil_check_name_string(listSet->fixedList[i].dirName, 1, CELL_SAVEDATA_DIRNAME_SIZE))
{ {
return false; case -1:
{
// ****** sysutil savedata parameter error : 40 ******
return {CELL_SAVEDATA_ERROR_PARAM, "40"};
}
case -2:
{
if (listSet->fixedList[i].dirName[0]) // ???
{
// ****** sysutil savedata parameter error : 41 ******
return {CELL_SAVEDATA_ERROR_PARAM, "41"};
}
break;
}
case 0: break;
default: ASSUME(0);
}
selected_list.emplace(listSet->fixedList[i].dirName);
}
// Clean save data list
save_entries.erase(std::remove_if(save_entries.begin(), save_entries.end(), [&selected_list](const SaveDataEntry& entry) -> bool
{
return selected_list.count(entry.dirName) == 0;
}), save_entries.end());
if (listSet->newData)
{
switch (listSet->newData->iconPosition)
{
case CELL_SAVEDATA_ICONPOS_HEAD:
case CELL_SAVEDATA_ICONPOS_TAIL:
break;
default:
{
// ****** sysutil savedata parameter error : 43 ******
return {CELL_SAVEDATA_ERROR_PARAM, "43"};
} }
} }
return true; if (!listSet->newData->dirName)
}), save_entries.end()); {
// ****** sysutil savedata parameter error : 44 ******
return {CELL_SAVEDATA_ERROR_PARAM, "44"};
}
switch (sysutil_check_name_string(listSet->newData->dirName.get_ptr(), 1, CELL_SAVEDATA_DIRNAME_SIZE))
{
case -1:
{
// ****** sysutil savedata parameter error : 45 ******
return {CELL_SAVEDATA_ERROR_PARAM, "45"};
}
case -2:
{
if (listSet->newData->dirName[0]) // ???
{
// ****** sysutil savedata parameter error : 4 ******
return {CELL_SAVEDATA_ERROR_PARAM, "46"};
}
break;
}
case 0: break;
default: ASSUME(0);
}
}
switch (const u32 pos_type = listSet->focusPosition) switch (const u32 pos_type = listSet->focusPosition)
{ {
case CELL_SAVEDATA_FOCUSPOS_DIRNAME: case CELL_SAVEDATA_FOCUSPOS_DIRNAME:
{ {
if (!listSet->focusDirName)
{
// ****** sysutil savedata parameter error : 35 ******
return {CELL_SAVEDATA_ERROR_PARAM, "35"};
}
switch (sysutil_check_name_string(listSet->focusDirName.get_ptr(), 1, CELL_SAVEDATA_DIRNAME_SIZE))
{
case -1:
{
// ****** sysutil savedata parameter error : 36 ******
return {CELL_SAVEDATA_ERROR_PARAM, "36"};
}
case -2:
{
if (listSet->focusDirName[0]) // ???
{
// ****** sysutil savedata parameter error : 37 ******
return {CELL_SAVEDATA_ERROR_PARAM, "37"};
}
break;
}
case 0: break;
default: ASSUME(0);
}
const std::string dirStr = listSet->focusDirName.get_ptr();
for (u32 i = 0; i < save_entries.size(); i++) for (u32 i = 0; i < save_entries.size(); i++)
{ {
if (save_entries[i].dirName == listSet->focusDirName.get_ptr()) if (save_entries[i].dirName == dirStr)
{ {
focused = i; focused = i;
break; break;
@ -772,6 +879,13 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
} }
case CELL_SAVEDATA_FOCUSPOS_NEWDATA: case CELL_SAVEDATA_FOCUSPOS_NEWDATA:
{ {
if (!listSet->newData)
{
// ****** sysutil savedata parameter error : 34 ******
cellSaveData.error("savedata_op(): listSet->newData is null while listSet->focusPosition is NEWDATA");
return {CELL_SAVEDATA_ERROR_PARAM, "34"};
}
//TODO: If adding the new data to the save_entries vector //TODO: If adding the new data to the save_entries vector
// to be displayed in the save mangaer UI, it should be focused here // to be displayed in the save mangaer UI, it should be focused here
break; break;
@ -1244,6 +1358,14 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
return {CELL_SAVEDATA_ERROR_PARAM, "58"}; return {CELL_SAVEDATA_ERROR_PARAM, "58"};
} }
} }
else
{
if (statSet->setParam->parental_level > 11)
{
// ****** sysutil savedata parameter error : 58 ******
return {CELL_SAVEDATA_ERROR_PARAM, "58"};
}
}
for (u8 resv : statSet->setParam->reserved) for (u8 resv : statSet->setParam->reserved)
{ {