mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-29 15:44:02 +00:00
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.
This commit is contained in:
parent
1db46a2345
commit
8c3f832f09
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user