From aea35ee7d293eddcf4dd27d3840cab274dc60516 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Mon, 22 Sep 2014 00:05:09 +0200 Subject: [PATCH] lx_fs: improve root directory handling - correctly catch and report non-existing root directories - remove *all* leading slashes from root-directory attributes and sanitize empty declarations to current working directory --- repos/os/src/server/lx_fs/main.cc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/repos/os/src/server/lx_fs/main.cc b/repos/os/src/server/lx_fs/main.cc index 0ad7fd8d59..b3884e030f 100644 --- a/repos/os/src/server/lx_fs/main.cc +++ b/repos/os/src/server/lx_fs/main.cc @@ -351,18 +351,21 @@ class File_system::Root : public Root_component /* * Make sure the root path is specified with a * leading path delimiter. For performing the - * lookup, we skip the first character. + * lookup, we remove all leading slashes. */ - if (root[0] != '/') - throw Lookup_failed(); + if (root[0] != '/') { + PERR("Root directory must start with / but is \"%s\"", root); + throw Root::Unavailable(); + } - root_dir = root + 1; + for (root_dir = root; *root_dir == '/'; ++root_dir) ; + + /* sanitize possibly empty root_dir to current directory */ + if (*root_dir == 0) + root_dir = "."; } catch (Xml_node::Nonexistent_attribute) { PERR("Missing \"root\" attribute in policy definition"); throw Root::Unavailable(); - } catch (Lookup_failed) { - PERR("Session root directory \"%s\" does not exist", root); - throw Root::Unavailable(); } /* @@ -392,8 +395,14 @@ class File_system::Root : public Root_component ram_quota, session_size); throw Root::Quota_exceeded(); } - return new (md_alloc()) - Session_component(tx_buf_size, _ep, root_dir, writeable, *md_alloc()); + + try { + return new (md_alloc()) + Session_component(tx_buf_size, _ep, root_dir, writeable, *md_alloc()); + } catch (Lookup_failed) { + PERR("Session root directory \"%s\" does not exist", root); + throw Root::Unavailable(); + } } public: