From b344f2bc39e1b7a28826bd5b11ed6969edf6e6a2 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Thu, 22 Mar 2018 18:49:47 +0100 Subject: [PATCH] nic_router: fix pure virtual call in Interface The Interface constructor previously tried to attach to a domain. This might include sending a DHCP request to get the domain a valid IP config. But in order to achieve this, the constructor used a pure virtual method of Interface which crashes due to the unfinished vtable. To fix this bug, the attach attempt was moved to a new Interface::init method. Issue #2730 --- repos/os/src/server/nic_router/component.cc | 5 ++++- repos/os/src/server/nic_router/interface.cc | 5 +++++ repos/os/src/server/nic_router/interface.h | 2 ++ repos/os/src/server/nic_router/main.cc | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/repos/os/src/server/nic_router/component.cc b/repos/os/src/server/nic_router/component.cc index f50af37154..210282cb5d 100644 --- a/repos/os/src/server/nic_router/component.cc +++ b/repos/os/src/server/nic_router/component.cc @@ -153,11 +153,14 @@ Session_component *Net::Root::_create_session(char const *args) throw Insufficient_ram_quota(); } Session_label const label(label_from_args(args)); - return new (md_alloc()) + Session_component &component = *new (md_alloc()) Session_component(*md_alloc(), _timer, ram_quota - session_size, _buf_ram, tx_buf_size, rx_buf_size, _region_map, _mac_alloc.alloc(), _ep, _router_mac, label, _interfaces, _config()); + + component.init(); + return &component; } catch (Mac_allocator::Alloc_failed) { error("failed to allocate MAC address"); diff --git a/repos/os/src/server/nic_router/interface.cc b/repos/os/src/server/nic_router/interface.cc index 855413712a..a31c62bd39 100644 --- a/repos/os/src/server/nic_router/interface.cc +++ b/repos/os/src/server/nic_router/interface.cc @@ -1131,6 +1131,11 @@ Interface::Interface(Genode::Entrypoint &ep, _interfaces(interfaces) { _interfaces.insert(this); +} + + +void Interface::init() +{ try { _attach_to_domain(_policy.determine_domain_name(), true); } catch (Domain_tree::No_match) { } } diff --git a/repos/os/src/server/nic_router/interface.h b/repos/os/src/server/nic_router/interface.h index 35a27c235d..3db14c124d 100644 --- a/repos/os/src/server/nic_router/interface.h +++ b/repos/os/src/server/nic_router/interface.h @@ -322,6 +322,8 @@ class Net::Interface : private Interface_list::Element void link_state_sigh(Genode::Signal_context_capability sigh); + void init(); + /*************** ** Accessors ** diff --git a/repos/os/src/server/nic_router/main.cc b/repos/os/src/server/nic_router/main.cc index 8c52cf2b54..9acd974490 100644 --- a/repos/os/src/server/nic_router/main.cc +++ b/repos/os/src/server/nic_router/main.cc @@ -81,6 +81,7 @@ Configuration &Net::Main::_init_config() Net::Main::Main(Env &env) : _env(env) { + _uplink.init(); _config_rom.sigh(_config_handler); env.parent().announce(env.ep().manage(_root)); }