Manually prevent placeholder/content appending

This commit is contained in:
Adubbz 2019-08-06 21:29:28 +10:00
parent 7bcf2276a7
commit 5e0f4130c4
3 changed files with 25 additions and 7 deletions

View file

@ -157,6 +157,14 @@ namespace sts::ncm {
auto file_guard = SCOPE_GUARD { fclose(f); };
u64 size = 0;
R_TRY(GetSizeFromPlaceHolderId(&size, placeholder_id));
/* We can't disable append with stdio, so check this manually. */
if (offset + data.num_elements > size) {
return ResultFileExtensionWithoutOpenModeAllowAppend;
}
if (fseek(f, offset, SEEK_SET) != 0) {
return fsdevGetLastResult();
}
@ -585,6 +593,14 @@ namespace sts::ncm {
fclose(f);
};
u64 size = 0;
R_TRY(GetSizeFromContentId(&size, content_id));
/* We can't disable append with stdio, so check this manually. */
if (offset + data.num_elements > size) {
return ResultFileExtensionWithoutOpenModeAllowAppend;
}
if (fseek(f, offset, SEEK_SET) != 0) {
return fsdevGetLastResult();
}

View file

@ -301,7 +301,7 @@ namespace sts::ncm {
/* We should be given a qualified path. */
if (!unqual_path || unqual_path > path + 0xf) {
return ResultFsUnqualifiedPath;
return ResultInvalidMountName;
}
strncpy(mount_name.name, path, unqual_path - path);

View file

@ -152,11 +152,13 @@ namespace sts::ncm {
typedef void (*MakePlaceHolderPathFunc)(char* out, PlaceHolderId placeholder_id, const char* root);
// TODO: Move to libstrat
static constexpr Result ResultNcmStoragePathNotFound = MAKERESULT(Module_Ncm, 1);
static constexpr Result ResultNcmInvalidPlaceHolderDirectoryEntry = MAKERESULT(Module_Ncm, 170);
static constexpr Result ResultNcmInvalidContentStorageOperation = MAKERESULT(Module_Ncm, 190);
static constexpr Result ResultNcmStorageRootNotFound = MAKERESULT(Module_Ncm, 310);
static constexpr Result ResultFsUnqualifiedPath = MAKERESULT(Module_Fs, 6065);
static constexpr Result ResultFsMountNameNotFound = MAKERESULT(Module_Fs, 6905);
static constexpr Result ResultNcmStoragePathNotFound = MAKERESULT(Module_Ncm, 1);
static constexpr Result ResultNcmInvalidPlaceHolderDirectoryEntry = MAKERESULT(Module_Ncm, 170);
static constexpr Result ResultNcmInvalidContentStorageOperation = MAKERESULT(Module_Ncm, 190);
static constexpr Result ResultNcmStorageRootNotFound = MAKERESULT(Module_Ncm, 310);
static constexpr Result ResultFileExtensionWithoutOpenModeAllowAppend = MAKERESULT(Module_Fs, 6201);
static constexpr Result ResultInvalidMountName = MAKERESULT(Module_Fs, 6065);
static constexpr Result ResultFsMountNameNotFound = MAKERESULT(Module_Fs, 6905);
}