nic session: fix quota check

Check for overflow.

Issue #1735
This commit is contained in:
Sebastian Sumpf
2015-10-07 10:38:41 +02:00
committed by Christian Helmuth
parent 5aec67d5bb
commit 78e18981fb
6 changed files with 18 additions and 30 deletions

View File

@ -166,12 +166,10 @@ class Nic::Root : public Genode::Root_component<Loopback_component>
/*
* Check if donated ram quota suffices for both communication
* buffers. Also check both sizes separately to handle a
* possible overflow of the sum of both sizes.
* buffers and check for overflow
*/
if (tx_buf_size > ram_quota - session_size
|| rx_buf_size > ram_quota - session_size
|| tx_buf_size + rx_buf_size > ram_quota - session_size) {
if (tx_buf_size + rx_buf_size < tx_buf_size ||
tx_buf_size + rx_buf_size > ram_quota - session_size) {
PERR("insufficient 'ram_quota', got %zd, need %zd",
ram_quota, tx_buf_size + rx_buf_size + session_size);
throw Root::Quota_exceeded();