Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/startup_stubs/runtime_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,8 @@ std::string update_container(u64 update)
{
std::string name;
AcquireSRWLockShared(&save_lock);
struct Unlock { ~Unlock() { ReleaseSRWLockShared(&save_lock); } } unlock;
if (update >= save_update_handle) name = save_table.update_container(static_cast<std::size_t>(update - save_update_handle));
ReleaseSRWLockShared(&save_lock);
return name;
}
#include "startup_stubs/save_read.inl"
Expand Down
19 changes: 14 additions & 5 deletions src/startup_stubs/save_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,21 @@ inline bool valid_name(std::string_view name) noexcept
same = std::tolower(static_cast<unsigned char>(tail[i])) == suffix[i];
if (same) return false;
}
std::string stem(name.substr(0, name.find('.')));
for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
while (!stem.empty() && stem.back() == ' ') stem.pop_back();
std::string_view stem = name.substr(0, name.find('.'));
while (!stem.empty() && stem.back() == ' ') stem.remove_suffix(1);
const auto upper = [](char c) { return static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); };
const auto matches = [&](std::string_view device) {
if (stem.size() != device.size()) return false;
for (std::size_t i = 0; i < stem.size(); ++i)
if (upper(stem[i]) != device[i]) return false;
return true;
};
for (const char* device : {"CON", "PRN", "AUX", "NUL"})
if (stem == device) return false;
if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false;
if (matches(device)) return false;
if (stem.size() == 4 && stem[3] >= '0' && stem[3] <= '9') {
stem.remove_suffix(1);
if (matches("COM") || matches("LPT")) return false;
}
return true;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/startup_gamesave_submit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ int run(bool system)
call(16,provider_handle,ptr("profile"),ptr(&container)) ||
call(23,container,0,ptr(&good)) || call(23,container,0,ptr(&bad))) return 1;
unsigned char byte=0x11;
const std::string long_name(80, 'c');
const std::string name_copy(long_name);
const std::size_t name_allocation = name_copy.capacity() + 1;
fail_allocation_size = name_allocation;
if (!x2w_save::valid_name(long_name) || fail_allocation_size != name_allocation) return 26;
fail_allocation_size = 0;
u64 long_container{}, long_update{};
if (call(16,provider_handle,ptr(long_name.c_str()),ptr(&long_container)) ||
call(23,long_container,0,ptr(&long_update))) return 22;
fail_allocation_size = name_allocation; // Fail the same string copy under save_lock.
const u64 name_copy_result = call(25,long_update,ptr("preference"),ptr(&byte),1);
if (fail_allocation_size || name_copy_result != e_outofmemory) return 23;
if (!TryAcquireSRWLockExclusive(&save_lock)) return 24;
ReleaseSRWLockExclusive(&save_lock);
if (call(25,long_update,ptr("preference"),ptr(&byte),1) || call(27,long_update)) return 25;
call(24,long_update);
call(17,long_container);
const std::array<unsigned char, 1025> large_blob{};
for (const auto data_size : {std::size_t{1}, large_blob.size()}) {
fail_allocation_size = data_size == 1 ? sizeof(x2w_save::Action) : data_size;
Expand Down
Loading