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
This commit is contained in:
Christian Helmuth 2014-09-22 00:05:09 +02:00
parent 96d9e442f5
commit aea35ee7d2
1 changed files with 18 additions and 9 deletions

View File

@ -351,18 +351,21 @@ class File_system::Root : public Root_component<Session_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<Session_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: