Skip to content

Passing None for args results in empty string passed to module #10

@jsturtevant

Description

@jsturtevant

When passing None to a loaded module, it causes the module to end up with one argument passed with a "":

let wasi_module = vm
            .wasi_module_mut()
            .ok_or_else(|| anyhow::Error::msg("Not found wasi module"))
            .map_err(|err| ExecutorError::Execution(err.into()))?;

wasi_module.initialize(
            None,
            Some(envs.iter().map(|s| s as &str).collect()),
            None,
        );

results in module that gets an arg:

fn main() {
    let args: Vec<_> = env::args().collect();
    let mut cmd = "daemon";
    if !args.is_empty() {
      //!! args isn't empy! it is ""
    }

See containerd/runwasi#146 (comment) for more info.

It looks like the code here is pushing something onto the args for the module:

pub fn init_wasi(
&mut self,
args: Option<Vec<&str>>,
envs: Option<Vec<&str>>,
preopens: Option<Vec<&str>>,
) {
// parse args
let cstr_args: Vec<_> = match args {
Some(args) => args
.iter()
.map(|&x| std::ffi::CString::new(x).unwrap())
.collect(),
None => vec![],
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions