Add NULL pointer checks to remote storage interface.

This commit is contained in:
Mr_Goldberg 2021-06-22 15:32:58 -04:00
parent b189fbf260
commit f4cd015701
No known key found for this signature in database
GPG key ID: 8597D87419DEF278

View file

@ -83,7 +83,7 @@ Steam_Remote_Storage(class Settings *settings, Local_Storage *local_storage, cla
bool FileWrite( const char *pchFile, const void *pvData, int32 cubData ) bool FileWrite( const char *pchFile, const void *pvData, int32 cubData )
{ {
PRINT_DEBUG("Steam_Remote_Storage::FileWrite %s %u\n", pchFile, cubData); PRINT_DEBUG("Steam_Remote_Storage::FileWrite %s %u\n", pchFile, cubData);
if (!pchFile || cubData <= 0 || cubData > k_unMaxCloudFileChunkSize) { if (!pchFile || cubData <= 0 || cubData > k_unMaxCloudFileChunkSize || !pvData) {
return false; return false;
} }
@ -96,6 +96,7 @@ bool FileWrite( const char *pchFile, const void *pvData, int32 cubData )
int32 FileRead( const char *pchFile, void *pvData, int32 cubDataToRead ) int32 FileRead( const char *pchFile, void *pvData, int32 cubDataToRead )
{ {
PRINT_DEBUG("Steam_Remote_Storage::FileRead %s %i\n", pchFile, cubDataToRead); PRINT_DEBUG("Steam_Remote_Storage::FileRead %s %i\n", pchFile, cubDataToRead);
if (!pchFile || !pvData || !cubDataToRead) return 0;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
int read_data = local_storage->get_data(Local_Storage::remote_storage_folder, pchFile, (char* )pvData, cubDataToRead); int read_data = local_storage->get_data(Local_Storage::remote_storage_folder, pchFile, (char* )pvData, cubDataToRead);
if (read_data < 0) read_data = 0; if (read_data < 0) read_data = 0;
@ -107,7 +108,7 @@ STEAM_CALL_RESULT( RemoteStorageFileWriteAsyncComplete_t )
SteamAPICall_t FileWriteAsync( const char *pchFile, const void *pvData, uint32 cubData ) SteamAPICall_t FileWriteAsync( const char *pchFile, const void *pvData, uint32 cubData )
{ {
PRINT_DEBUG("Steam_Remote_Storage::FileWriteAsync\n"); PRINT_DEBUG("Steam_Remote_Storage::FileWriteAsync\n");
if (!pchFile || cubData > k_unMaxCloudFileChunkSize || cubData == 0) { if (!pchFile || cubData > k_unMaxCloudFileChunkSize || cubData == 0 || !pvData) {
return k_uAPICallInvalid; return k_uAPICallInvalid;
} }
@ -124,6 +125,7 @@ STEAM_CALL_RESULT( RemoteStorageFileReadAsyncComplete_t )
SteamAPICall_t FileReadAsync( const char *pchFile, uint32 nOffset, uint32 cubToRead ) SteamAPICall_t FileReadAsync( const char *pchFile, uint32 nOffset, uint32 cubToRead )
{ {
PRINT_DEBUG("Steam_Remote_Storage::FileReadAsync\n"); PRINT_DEBUG("Steam_Remote_Storage::FileReadAsync\n");
if (!pchFile) return k_uAPICallInvalid;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
unsigned int size = local_storage->file_size(Local_Storage::remote_storage_folder, pchFile); unsigned int size = local_storage->file_size(Local_Storage::remote_storage_folder, pchFile);
@ -151,6 +153,7 @@ SteamAPICall_t FileReadAsync( const char *pchFile, uint32 nOffset, uint32 cubToR
bool FileReadAsyncComplete( SteamAPICall_t hReadCall, void *pvBuffer, uint32 cubToRead ) bool FileReadAsyncComplete( SteamAPICall_t hReadCall, void *pvBuffer, uint32 cubToRead )
{ {
PRINT_DEBUG("Steam_Remote_Storage::FileReadAsyncComplete\n"); PRINT_DEBUG("Steam_Remote_Storage::FileReadAsyncComplete\n");
if (!pvBuffer) return false;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto a_read = std::find_if(async_reads.begin(), async_reads.end(), [&hReadCall](Async_Read const& item) { return item.api_call == hReadCall; }); auto a_read = std::find_if(async_reads.begin(), async_reads.end(), [&hReadCall](Async_Read const& item) { return item.api_call == hReadCall; });
@ -190,6 +193,7 @@ STEAM_CALL_RESULT( RemoteStorageFileShareResult_t )
SteamAPICall_t FileShare( const char *pchFile ) SteamAPICall_t FileShare( const char *pchFile )
{ {
PRINT_DEBUG("Steam_Remote_Storage::FileShare\n"); PRINT_DEBUG("Steam_Remote_Storage::FileShare\n");
if (!pchFile) return k_uAPICallInvalid;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
RemoteStorageFileShareResult_t data = {}; RemoteStorageFileShareResult_t data = {};
if (local_storage->file_exists(Local_Storage::remote_storage_folder, pchFile)) { if (local_storage->file_exists(Local_Storage::remote_storage_folder, pchFile)) {