Add size limit for files.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
4ce4fdd4fd
commit
8dd890c200
|
@ -58,6 +58,11 @@ entry_type parse_formdata()
|
|||
const auto screenshot = cgi.getFile("screenshot");
|
||||
if (screenshot != cgi.getFiles().end())
|
||||
{
|
||||
constexpr size_t size_limit{1024 * 1024 * 2}; // 2 MiB.
|
||||
if (screenshot->getDataLength() > size_limit)
|
||||
{
|
||||
throw runtime_error{"Filesize too big"};
|
||||
}
|
||||
string filepath{fs::temp_directory_path()
|
||||
/ "fediblock-backend-XXXXXX"};
|
||||
if (mkstemp(&filepath[0]) == -1) // mkstemp() modifies filepath.
|
||||
|
@ -82,7 +87,7 @@ entry_type parse_formdata()
|
|||
catch (const exception &e)
|
||||
{
|
||||
cerr << e.what() << '\n';
|
||||
// TODO: Error handling.
|
||||
// TODO: Make errors visible to the user in a helpful way.
|
||||
}
|
||||
|
||||
return entry;
|
||||
|
|
Reference in New Issue