Skip to content

Commit

Permalink
cellSaveData: Add some error checks for fixedSet, fileSet params
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Mar 1, 2020
1 parent fbe6900 commit f851f21
Showing 1 changed file with 105 additions and 8 deletions.
113 changes: 105 additions & 8 deletions rpcs3/Emu/Cell/Modules/cellSaveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,18 +944,42 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
return {CELL_SAVEDATA_ERROR_PARAM, "26"};
}

switch (sysutil_check_name_string(fixedSet->dirName.get_ptr(), 1, CELL_SAVEDATA_DIRNAME_SIZE))
{
case -1:
{
// ****** sysutil savedata parameter error : 27 ******
return {CELL_SAVEDATA_ERROR_PARAM, "27"};
}
case -2:
{
// ****** sysutil savedata parameter error : 28 ******
return {CELL_SAVEDATA_ERROR_PARAM, "28"};
}
case 0: break;
default: ASSUME(0);
}

const std::string dirStr = fixedSet->dirName.get_ptr();

for (u32 i = 0; i < save_entries.size(); i++)
{
if (save_entries[i].dirName == fixedSet->dirName.get_ptr())
if (save_entries[i].dirName == dirStr)
{
selected = i;
break;
}
}

if (fixedSet->option != CELL_SAVEDATA_OPTION_NOCONFIRM &&
(operation == SAVEDATA_OP_FIXED_SAVE || operation == SAVEDATA_OP_FIXED_LOAD || operation == SAVEDATA_OP_FIXED_DELETE))
switch (fixedSet->option)
{
case CELL_SAVEDATA_OPTION_NONE:
{
if (operation != SAVEDATA_OP_FIXED_SAVE && operation != SAVEDATA_OP_FIXED_LOAD && operation != SAVEDATA_OP_FIXED_DELETE)
{
break;
}

std::string message;

if (selected == -1)
Expand Down Expand Up @@ -990,11 +1014,20 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
{
return CELL_CANCEL;
}

break;
}
case CELL_SAVEDATA_OPTION_NOCONFIRM:
break;

default :
// ****** sysutil savedata parameter error : 81 ******
return {CELL_SAVEDATA_ERROR_PARAM, "81"};
}

if (selected == -1)
{
save_entry.dirName = fixedSet->dirName.get_ptr();
save_entry.dirName = dirStr;
save_entry.escaped = vfs::escape(save_entry.dirName);
}

Expand Down Expand Up @@ -1364,7 +1397,55 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
return {CELL_SAVEDATA_ERROR_PARAM, "69"};
}

file_path = fileSet->fileName.get_ptr();
const auto fileName = fileSet->fileName.get_ptr();

const auto termpos = std::find(fileName, fileName + CELL_SAVEDATA_FILENAME_SIZE, '\0');

if (termpos == fileName + CELL_SAVEDATA_FILENAME_SIZE)
{
// ****** sysutil savedata parameter error : 71 ******
return {CELL_SAVEDATA_ERROR_PARAM, "71"};
}

const auto dotpos = std::find(fileName, termpos, '.');

if (dotpos != termpos && (dotpos > fileName + 8 || termpos - dotpos > 4))
{
// ****** sysutil savedata parameter error : 70 ******
return {CELL_SAVEDATA_ERROR_PARAM, "70"};
}

char name[10];

if (dotpos != fileName)
{
// Reset for filename
std::memset(name, 0, 10);
std::copy(fileName, dotpos, name);

// Check filename
if (sysutil_check_name_string(name, 1, 9) == -1)
{
// ****** sysutil savedata parameter error : 70 ******
return {CELL_SAVEDATA_ERROR_PARAM, "70"};
}
}

if (dotpos != termpos)
{
// Reset for file extension
std::memset(name, 0, 5);
std::copy(dotpos, termpos, name);

// Check file extension
if (sysutil_check_name_string(name, 1, 4) == -1)
{
// ****** sysutil savedata parameter error : 70 ******
return {CELL_SAVEDATA_ERROR_PARAM, "70"};
}
}

file_path = fileName;

if (type == CELL_SAVEDATA_FILETYPE_SECUREFILE)
{
Expand Down Expand Up @@ -1436,6 +1517,12 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
{
fs::file& file = all_files[file_path];

// TODO: Check this
//if (!fileSet->fileSize)
//{
// break;
//}

if (!file)
{
// ****** sysutil savedata parameter error : 22 ******
Expand All @@ -1451,7 +1538,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
break;
}

if (!fileSet->fileBuf)
if (!fileSet->fileBuf && fileSet->fileBufSize)
{
// ****** sysutil savedata parameter error : 73 ******
savedata_result = {CELL_SAVEDATA_ERROR_PARAM, "73"};
Expand All @@ -1469,6 +1556,11 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
{
fs::file& file = all_files[file_path];

//if (!fileSet->fileSize)
//{
// break;
//}

if (!file)
{
file = fs::make_stream<std::vector<uchar>>();
Expand All @@ -1481,7 +1573,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
break;
}

if (!fileSet->fileBuf)
if (!fileSet->fileBuf && fileSet->fileBufSize)
{
// ****** sysutil savedata parameter error : 73 ******
savedata_result = {CELL_SAVEDATA_ERROR_PARAM, "73"};
Expand Down Expand Up @@ -1515,6 +1607,11 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
{
fs::file& file = all_files[file_path];

//if (!fileSet->fileSize)
//{
// break;
//}

if (!file)
{
file = fs::make_stream<std::vector<uchar>>();
Expand All @@ -1527,7 +1624,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
break;
}

if (!fileSet->fileBuf)
if (!fileSet->fileBuf && fileSet->fileBufSize)
{
// ****** sysutil savedata parameter error : 73 ******
savedata_result = {CELL_SAVEDATA_ERROR_PARAM, "73"};
Expand Down

0 comments on commit f851f21

Please sign in to comment.