Avoid out of memory with cellGameGetParamString

This commit is contained in:
Eladash 2020-02-03 00:03:52 +02:00 committed by Ivan
parent 9d9b5c4d66
commit 4488312e81

View File

@ -837,10 +837,17 @@ error_code cellGameGetParamString(s32 id, vm::ptr<char> buf, u32 bufsize)
return CELL_GAME_ERROR_NOTSUPPORTED;
}
std::string value = psf::get_string(prm->sfo, std::string(key.name));
value.resize(bufsize - 1);
const std::string value = psf::get_string(prm->sfo, std::string(key.name));
const auto value_size = value.size() + 1;
std::memcpy(buf.get_ptr(), value.c_str(), bufsize);
const auto pbuf = buf.get_ptr();
const bool to_pad = bufsize > value_size;
std::memcpy(pbuf, value.c_str(), to_pad ? value_size : bufsize);
if (to_pad)
{
std::memset(pbuf + value_size, 0, bufsize - value_size);
}
return CELL_OK;
}