From 8c3f832f0943efe2028c4a0b1e0fd0bedfcca790 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 8 Jan 2012 21:15:43 +0100 Subject: [PATCH] Noux: quote env values, fix #66 When reading the values of environment variables supplied via Genode config mechanism, the XML attribute values were taken as is. On the libc side, however, the values are processed using Genode's 'Arg_string' functions. When unquoted, 'Arg_string' expects values to be either identifiers or numbers. In the general case, however, env values cannot be expected to satisfy these requirements. Hence, it is better to always quote these values when reading the XML config. An alternative (maybe better) solution would be to not use the 'Arg_string' classes in the libc side. --- ports/src/noux/main.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ports/src/noux/main.cc b/ports/src/noux/main.cc index 418ae6a3e..8c304a950 100644 --- a/ports/src/noux/main.cc +++ b/ports/src/noux/main.cc @@ -337,6 +337,26 @@ static Noux::Args const &args_of_init_process() } +static void quote(char *buf, Genode::size_t buf_len) +{ + char c = '"'; + + /* + * Make sure to leave space at the end of buffer for the finishing '"' and + * the null-termination. + */ + unsigned i = 0; + for (; c && (i + 2 < buf_len); i++) + { + char next_c = buf[i]; + buf[i] = c; + c = next_c; + } + buf[i + 0] = '"'; + buf[i + 1] = 0; +} + + /** * Return string containing the environment variables of init * @@ -357,6 +377,7 @@ static char const *env_string_of_init_process() arg_node.attribute("name").value(name_buf, sizeof(name_buf)); arg_node.attribute("value").value(value_buf, sizeof(value_buf)); + quote(value_buf, sizeof(value_buf)); Genode::Arg_string::set_arg(env_buf, sizeof(env_buf), name_buf, value_buf);