Skip to content

Commit 904fcfc

Browse files
authored
Merge branch 'master' into button-fix
2 parents 9847d2e + 7be182e commit 904fcfc

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

rpcs3/Emu/NP/clans_client.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
LOG_CHANNEL(clan_log, "clans");
3232

33-
3433
const char* REQ_TYPE_FUNC = "func";
3534
const char* REQ_TYPE_SEC = "sec";
3635

@@ -128,6 +127,11 @@ void fmt_class_string<clan::ClanRequestAction>::format(std::string& out, u64 arg
128127

129128
namespace clan
130129
{
130+
constexpr size_t base64_size(size_t size)
131+
{
132+
return (size + 2) / 3 * 4 + 1;
133+
}
134+
131135
size_t clans_client::curl_write_callback(void* data, size_t size, size_t nmemb, void* clientp)
132136
{
133137
const size_t realsize = size * nmemb;
@@ -341,11 +345,16 @@ namespace clan
341345
return "";
342346
}
343347

344-
std::vector<byte> ticket_bytes(1024);
345-
uint32_t ticket_size = UINT32_MAX;
348+
std::vector<byte> ticket_bytes(base64_size(clan_ticket.size()));
349+
uint32_t encoded_ticket_size = ::size32(ticket_bytes);
350+
351+
if (Base64_Encode_NoNl(clan_ticket.data(), ::size32(clan_ticket), ticket_bytes.data(), &encoded_ticket_size) != 0)
352+
{
353+
clan_log.error("Failed to encode clan ticket to base64");
354+
return "";
355+
}
346356

347-
Base64_Encode_NoNl(clan_ticket.data(), static_cast<u32>(clan_ticket.size()), ticket_bytes.data(), &ticket_size);
348-
const std::string ticket_str = std::string(reinterpret_cast<char*>(ticket_bytes.data()), ticket_size);
357+
const std::string ticket_str = std::string(reinterpret_cast<char*>(ticket_bytes.data()), encoded_ticket_size);
349358

350359
return ticket_str;
351360
}
@@ -923,11 +932,14 @@ namespace clan
923932

924933
pugi::xml_node status = clan.append_child("bin-attr1"sv);
925934

935+
const u32 bin_data_size = static_cast<u32>(info.binData1Size);
936+
if (bin_data_size > sizeof(info.binAttr1))
937+
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
938+
926939
byte bin_attr_1[SCE_NP_CLANS_MEMBER_BINARY_ATTRIBUTE1_MAX_SIZE * 2 + 1] = {0};
927-
uint32_t bin_attr_1_size = UINT32_MAX;
928-
Base64_Encode_NoNl(info.binAttr1, info.binData1Size, bin_attr_1, &bin_attr_1_size);
940+
uint32_t bin_attr_1_size = sizeof(bin_attr_1);
929941

930-
if (bin_attr_1_size == UINT32_MAX)
942+
if (Base64_Encode_NoNl(info.binAttr1, bin_data_size, bin_attr_1, &bin_attr_1_size) != 0)
931943
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
932944

933945
// `reinterpret_cast` used to let the compiler select the correct overload of `set`

0 commit comments

Comments
 (0)