From 3adb7f991889b7bd3a152841d6fda0cfe9165bc4 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Mon, 3 Jun 2019 10:48:28 +1000 Subject: [PATCH] Version checking, ensure output pointers are non-null --- nx/include/switch/services/fs.h | 4 ++++ nx/source/services/fs.c | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 3f8df190..d9499025 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -188,7 +188,11 @@ Result fsOpenDataStorageByCurrentProcess(FsStorage* out); Result fsOpenDataStorageByDataId(FsStorage* out, u64 dataId, FsStorageId storageId); Result fsOpenDeviceOperator(FsDeviceOperator* out); Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out); + +// Retrieves the rights id corresponding to the content path. Only available on [2.0.0+]. Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id); + +// Retrieves the rights id and key generation corresponding to the content path. Only available on [3.0.0+]. Result fsGetRightsIdAndKeyGenerationByPath(const char* path, u8* out_key_generation, FsRightsId* out_rights_id); // todo: Rest of commands here diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 40361cef..3851a272 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -504,6 +504,9 @@ Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out) { } Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + char send_path[FS_MAX_PATH] = {0}; IpcCommand c; ipcInitialize(&c); @@ -535,7 +538,7 @@ Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id) { rc = resp->result; if (R_SUCCEEDED(rc)) { - *out_rights_id = resp->rights_id; + if (out_rights_id) *out_rights_id = resp->rights_id; } } @@ -543,6 +546,9 @@ Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id) { } Result fsGetRightsIdAndKeyGenerationByPath(const char* path, u8* out_key_generation, FsRightsId* out_rights_id) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + char send_path[FS_MAX_PATH] = {0}; IpcCommand c; ipcInitialize(&c); @@ -576,8 +582,8 @@ Result fsGetRightsIdAndKeyGenerationByPath(const char* path, u8* out_key_generat rc = resp->result; if (R_SUCCEEDED(rc)) { - *out_key_generation = resp->key_generation; - *out_rights_id = resp->rights_id; + if (out_key_generation) *out_key_generation = resp->key_generation; + if (out_rights_id) *out_rights_id = resp->rights_id; } }