mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-21 02:01:38 +00:00
Root_component::session: Fix ram_quota handling
You cannot check an unsigned size_t variable for underflow, so I changed the code to first check if an underflow would occur before performing the subtraction. Fixes #489.
This commit is contained in:
parent
7d30ffc907
commit
d5a758ea10
@ -186,14 +186,16 @@ namespace Genode {
|
||||
* the size of the session object.
|
||||
*/
|
||||
size_t ram_quota = Arg_string::find_arg(args.string(), "ram_quota").long_value(0);
|
||||
size_t const remaining_ram_quota = ram_quota - sizeof(SESSION_TYPE) -
|
||||
md_alloc()->overhead(sizeof(SESSION_TYPE));
|
||||
if (remaining_ram_quota < 0) {
|
||||
size_t needed = sizeof(SESSION_TYPE) + md_alloc()->overhead(sizeof(SESSION_TYPE));
|
||||
|
||||
if (needed > ram_quota) {
|
||||
PERR("Insufficient ram quota, provided=%zd, required=%zd",
|
||||
ram_quota, sizeof(SESSION_TYPE) + md_alloc()->overhead(sizeof(SESSION_TYPE)));
|
||||
ram_quota, needed);
|
||||
throw Root::Quota_exceeded();
|
||||
}
|
||||
|
||||
size_t const remaining_ram_quota = ram_quota - needed;
|
||||
|
||||
/*
|
||||
* Deduce ram quota needed for allocating the session object from the
|
||||
* donated ram quota.
|
||||
|
Loading…
x
Reference in New Issue
Block a user