Skip to content

Commit

Permalink
Merge pull request #4735 from wasmerio/fix-traversal-in-path-create
Browse files Browse the repository at this point in the history
Add traversal for `Root` inode
  • Loading branch information
syrusakbary authored May 31, 2024
2 parents 948a801 + 13a8e8e commit 1414570
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
24 changes: 14 additions & 10 deletions lib/wasix/src/syscalls/wasi/path_create_directory.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{path::PathBuf, str::FromStr};

use super::*;
use crate::syscalls::*;

Expand Down Expand Up @@ -57,13 +59,7 @@ pub(crate) fn path_create_directory_internal(
let env = ctx.data();
let (memory, state, inodes) = unsafe { env.get_memory_and_wasi_state_and_inodes(&ctx, 0) };
let working_dir = state.fs.get_fd(fd)?;
{
let guard = working_dir.inode.read();
if let Kind::Root { .. } = guard.deref() {
trace!("root has no rights to create a directories");
return Err(Errno::Access);
}
}

if !working_dir.rights.contains(Rights::PATH_CREATE_DIRECTORY) {
trace!("working directory (fd={fd}) has no rights to create a directory");
return Err(Errno::Access);
Expand Down Expand Up @@ -151,9 +147,17 @@ pub(crate) fn path_create_directory_internal(
cur_dir_inode = new_inode;
}
}
Kind::Root { .. } => {
trace!("the root node can no create a directory");
return Err(Errno::Access);
Kind::Root { entries } => {
match comp.borrow() {
"." | ".." => continue,
_ => (),
}
if let Some(child) = entries.get(comp) {
cur_dir_inode = child.clone();
} else {
trace!("the root node can no create a directory");
return Err(Errno::Access);
}
}
_ => {
trace!("path is not a directory");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import tempfile
import sys

temp_dir = tempfile.mkdtemp(prefix='pip-a-')
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import subprocess

result = subprocess.run(["/bin/python", '/code/child.py'], capture_output=True, text=True)

print(f"{result.returncode}", end="")
6 changes: 5 additions & 1 deletion tests/integration/cli/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ use std::path::{Path, PathBuf};

use crate::{asset_path, c_asset_path};

pub fn resources() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("resources")
}

pub fn php() -> (PathBuf, PathBuf, PathBuf) {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let resources = root.join("resources").join("php");
let resources = resources().join("php");
(
root.join("tests").join("wasm").join("php.wasm"),
resources.clone(),
Expand Down
19 changes: 18 additions & 1 deletion tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use reqwest::{blocking::Client, IntoUrl};
use tempfile::TempDir;
use wasmer_integration_tests_cli::{
asset_path,
fixtures::{self, php},
fixtures::{self, php, resources},
get_wasmer_path,
};

Expand Down Expand Up @@ -47,6 +47,23 @@ static CACHE_RUST_LOG: Lazy<String> = Lazy::new(|| {
.join(",")
});

#[test]
fn run_python_create_temp_dir_in_subprocess() {
let resources = resources().join("python").join("temp-dir-in-child");

let output = Command::new(get_wasmer_path())
.arg("run")
.arg("python/python")
.arg("--mapdir")
.arg(format!("/code:{}", resources.display()))
.arg("--")
.arg("/code/main.py")
.output()
.unwrap();

assert_eq!(output.stdout, "0".as_bytes().to_vec());
}

#[test]
fn run_php_with_sqlite() {
let (php_wasm, app_dir, db) = php();
Expand Down

0 comments on commit 1414570

Please sign in to comment.