Files
AnyPS5/core/libs/tests/GuestContentExport.cpp
T
Dean Galvin 48687eefab fix(contentexport): refuse init parameters without allocators or with reserved fields set
sceContentExportInit2 accepted any non-null parameter block. It now throws
when the malloc or free function is missing or a reserved field is not
zero. A test covers these refusals and the init and term order.
2026-09-30 18:35:36 +03:00

43 lines
1.2 KiB
C++

#include "SceTypes.hpp"
#include <cstdlib>
#include <stdexcept>
extern "C" int APS5_VABI sceContentExportInit2(const ContentExportInitParam2* init_param);
extern "C" int APS5_VABI sceContentExportTerm(void);
namespace {
void Require(bool value) { if (!value) std::abort(); }
template <typename TAction>
bool Throws(TAction action) {
try {
action();
} catch (const std::logic_error&) {
return true;
}
return false;
}
int allocator = 0;
}
int main() {
ContentExportInitParam2 param{&allocator, &allocator, nullptr, 0x10000, 0, 0};
Require(Throws([] { sceContentExportInit2(nullptr); }));
Require(Throws([] { sceContentExportTerm(); }));
ContentExportInitParam2 missing = param;
missing.free_func = nullptr;
Require(Throws([&] { sceContentExportInit2(&missing); }));
ContentExportInitParam2 reserved = param;
reserved.reserved1 = 1;
Require(Throws([&] { sceContentExportInit2(&reserved); }));
Require(sceContentExportInit2(&param) == 0);
Require(Throws([&] { sceContentExportInit2(&param); }));
Require(sceContentExportTerm() == 0);
Require(Throws([] { sceContentExportTerm(); }));
Require(sceContentExportInit2(&param) == 0);
Require(sceContentExportTerm() == 0);
}