|
30 | 30 |
|
31 | 31 | LOG_CHANNEL(clan_log, "clans"); |
32 | 32 |
|
33 | | - |
34 | 33 | const char* REQ_TYPE_FUNC = "func"; |
35 | 34 | const char* REQ_TYPE_SEC = "sec"; |
36 | 35 |
|
@@ -128,6 +127,11 @@ void fmt_class_string<clan::ClanRequestAction>::format(std::string& out, u64 arg |
128 | 127 |
|
129 | 128 | namespace clan |
130 | 129 | { |
| 130 | + constexpr size_t base64_size(size_t size) |
| 131 | + { |
| 132 | + return (size + 2) / 3 * 4 + 1; |
| 133 | + } |
| 134 | + |
131 | 135 | size_t clans_client::curl_write_callback(void* data, size_t size, size_t nmemb, void* clientp) |
132 | 136 | { |
133 | 137 | const size_t realsize = size * nmemb; |
@@ -341,11 +345,16 @@ namespace clan |
341 | 345 | return ""; |
342 | 346 | } |
343 | 347 |
|
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 | + } |
346 | 356 |
|
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); |
349 | 358 |
|
350 | 359 | return ticket_str; |
351 | 360 | } |
@@ -923,11 +932,14 @@ namespace clan |
923 | 932 |
|
924 | 933 | pugi::xml_node status = clan.append_child("bin-attr1"sv); |
925 | 934 |
|
| 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 | + |
926 | 939 | 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); |
929 | 941 |
|
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) |
931 | 943 | return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT; |
932 | 944 |
|
933 | 945 | // `reinterpret_cast` used to let the compiler select the correct overload of `set` |
|
0 commit comments