Skip to content
Permalink
Browse files

Merge pull request #11293 from unknownbrackets/savedata

Savedata: Correct use of bufSize/size
  • Loading branch information...
hrydgard committed Aug 12, 2018
2 parents 1fdb1f7 + b64bb2e commit 90edace7c7a80ff36e86b4bcd862fd6143f0caed
@@ -1101,21 +1101,14 @@ void PSPSaveDialog::ExecuteNotVisibleIOAction() {
// TODO: Should reset the directory's other files.
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATA:
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE:
if (param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE) == 0) {
result = 0;
} else if (MemoryStick_FreeSpace() == 0) {
result = param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE);
if (result == SCE_UTILITY_SAVEDATA_ERROR_SAVE_MS_NOSPACE) {
result = SCE_UTILITY_SAVEDATA_ERROR_RW_MEMSTICK_FULL;
} else {
result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
}
break;
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA:
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE:
if (param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE) == 0) {
result = 0;
} else {
result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
}
result = param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE);
break;
case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
@@ -362,6 +362,21 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD
if (!param) {
return SCE_UTILITY_SAVEDATA_ERROR_SAVE_MS_NOSPACE;
}
if (param->dataSize > param->dataBufSize) {
ERROR_LOG_REPORT(SCEUTILITY, "Savedata buffer overflow: %d / %d", param->dataSize, param->dataBufSize);
return SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_PARAMS;
}
auto validateSize = [](const PspUtilitySavedataFileData &data) {
if (data.buf.IsValid() && data.bufSize < data.size) {
ERROR_LOG_REPORT(SCEUTILITY, "Savedata subdata buffer overflow: %d / %d", data.size, data.bufSize);
return false;
}
return true;
};
if (!validateSize(param->icon0FileData) || !validateSize(param->icon1FileData) || !validateSize(param->pic1FileData) || !validateSize(param->snd0FileData)) {
return SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_PARAMS;
}

if (param->secureVersion > 3) {
ERROR_LOG_REPORT(SCEUTILITY, "Savedata version requested on save: %d", param->secureVersion);
return SCE_UTILITY_SAVEDATA_ERROR_SAVE_PARAM;
@@ -520,26 +535,26 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD
if (param->icon0FileData.buf.IsValid())
{
std::string icon0path = dirPath + "/" + ICON0_FILENAME;
WritePSPFile(icon0path, param->icon0FileData.buf, param->icon0FileData.bufSize);
WritePSPFile(icon0path, param->icon0FileData.buf, param->icon0FileData.size);
}
// SAVE ICON1
if (param->icon1FileData.buf.IsValid())
{
std::string icon1path = dirPath + "/" + ICON1_FILENAME;
WritePSPFile(icon1path, param->icon1FileData.buf, param->icon1FileData.bufSize);
WritePSPFile(icon1path, param->icon1FileData.buf, param->icon1FileData.size);
}
// SAVE PIC1
if (param->pic1FileData.buf.IsValid())
{
std::string pic1path = dirPath + "/" + PIC1_FILENAME;
WritePSPFile(pic1path, param->pic1FileData.buf, param->pic1FileData.bufSize);
WritePSPFile(pic1path, param->pic1FileData.buf, param->pic1FileData.size);
}

// Save SND
if (param->snd0FileData.buf.IsValid())
{
std::string snd0path = dirPath + "/" + SND0_FILENAME;
WritePSPFile(snd0path, param->snd0FileData.buf, param->snd0FileData.bufSize);
WritePSPFile(snd0path, param->snd0FileData.buf, param->snd0FileData.size);
}

return 0;
@@ -193,7 +193,7 @@ const CommonCommandTableEntry commonCommandTable[] = {
{ GE_CMD_VIEWPORTYCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
{ GE_CMD_VIEWPORTZSCALE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_DEPTHRANGE | DIRTY_PROJMATRIX | DIRTY_VIEWPORTSCISSOR_STATE },
{ GE_CMD_VIEWPORTZCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_DEPTHRANGE | DIRTY_PROJMATRIX | DIRTY_VIEWPORTSCISSOR_STATE },
{ GE_CMD_CLIPENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_RASTER_STATE },
{ GE_CMD_DEPTHCLAMPENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_RASTER_STATE },

// Z clip
{ GE_CMD_MINZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE | DIRTY_VIEWPORTSCISSOR_STATE },
@@ -297,8 +297,8 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer, int bufsize) {
}
break;

case GE_CMD_CLIPENABLE:
snprintf(buffer, bufsize, "Clip enable: %i", data);
case GE_CMD_DEPTHCLAMPENABLE:
snprintf(buffer, bufsize, "Depth clamp enable: %i", data);
break;

case GE_CMD_CULLFACEENABLE:
@@ -137,8 +137,8 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) {
}
break;

case GE_CMD_CLIPENABLE:
DEBUG_LOG(G3D, "DL Clip Enable: %i (ignoring)", data);
case GE_CMD_DEPTHCLAMPENABLE:
DEBUG_LOG(G3D, "DL Depth Clamp Enable: %i (ignoring)", data);
//we always clip, this is opengl
break;

@@ -506,7 +506,7 @@ void SoftGPU::ExecuteOp(u32 op, u32 diff) {
case GE_CMD_REGION2:
break;

case GE_CMD_CLIPENABLE:
case GE_CMD_DEPTHCLAMPENABLE:
break;

case GE_CMD_CULLFACEENABLE:
@@ -43,7 +43,7 @@ enum GECommand {
GE_CMD_LIGHTENABLE1 = 0x19,
GE_CMD_LIGHTENABLE2 = 0x1A,
GE_CMD_LIGHTENABLE3 = 0x1B,
GE_CMD_CLIPENABLE = 0x1C,
GE_CMD_DEPTHCLAMPENABLE = 0x1C,
GE_CMD_CULLFACEENABLE = 0x1D,
GE_CMD_TEXTUREMAPENABLE = 0x1E,
GE_CMD_FOGENABLE = 0x1F,
@@ -100,7 +100,7 @@ static const TabStateRow stateFlagsRows[] = {
{ L"Light 1 enable", GE_CMD_LIGHTENABLE1, CMD_FMT_FLAG },
{ L"Light 2 enable", GE_CMD_LIGHTENABLE2, CMD_FMT_FLAG },
{ L"Light 3 enable", GE_CMD_LIGHTENABLE3, CMD_FMT_FLAG },
{ L"Clip enable", GE_CMD_CLIPENABLE, CMD_FMT_FLAG },
{ L"Depth clamp enable", GE_CMD_DEPTHCLAMPENABLE, CMD_FMT_FLAG },
{ L"Cullface enable", GE_CMD_CULLFACEENABLE, CMD_FMT_FLAG },
{ L"Texture map enable", GE_CMD_TEXTUREMAPENABLE, CMD_FMT_FLAG },
{ L"Fog enable", GE_CMD_FOGENABLE, CMD_FMT_FLAG },

0 comments on commit 90edace

Please sign in to comment.
You can’t perform that action at this time.