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:
Torsten Hilbrich 2012-11-14 12:12:49 +01:00 committed by Norman Feske
parent 7d30ffc907
commit d5a758ea10
1 changed files with 6 additions and 4 deletions

View File

@ -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.