MCPcopy Create free account
hub / github.com/PLSysSec/wave / wasi_path_link

Function wasi_path_link

src/wrappers.rs:569–622  ·  view source on GitHub ↗
(
    ctx: &VmCtx,
    v_old_fd: u32,
    flags: u32,
    old_pathname: u32,
    old_path_len: u32,
    v_new_fd: u32,
    new_pathname: u32,
    new_path_len: u32,
)

Source from the content-addressed store, hash-verified

567#[ensures(ctx_safe(ctx))]
568#[ensures(trace_safe(trace, ctx))]
569pub fn wasi_path_link(
570 ctx: &VmCtx,
571 v_old_fd: u32,
572 flags: u32,
573 old_pathname: u32,
574 old_path_len: u32,
575 v_new_fd: u32,
576 new_pathname: u32,
577 new_path_len: u32,
578) -> RuntimeResult<()> {
579 let flags = LookupFlags::new(flags);
580
581 // let old_fd = ctx.fdmap.fd_to_native(v_old_fd)?;
582 // let new_fd = ctx.fdmap.fd_to_native(v_new_fd)?;
583
584 if v_old_fd != HOMEDIR_FD {
585 return Err(Enotcapable);
586 }
587 assert!(v_old_fd == HOMEDIR_FD);
588 let old_fd = ctx.homedir_host_fd;
589
590 if v_new_fd != HOMEDIR_FD {
591 return Err(Enotcapable);
592 }
593 assert!(v_new_fd == HOMEDIR_FD);
594 let new_fd = ctx.homedir_host_fd;
595
596 let should_follow = flags.should_follow();
597
598 // when resolveing paths for path_link, we resolve the final symlink
599 let old_host_pathname = ctx.translate_path(old_pathname, old_path_len, should_follow, old_fd);
600 unwrap_result!(old_host_pathname);
601 let new_host_pathname = ctx.translate_path(new_pathname, new_path_len, should_follow, new_fd);
602 unwrap_result!(new_host_pathname);
603
604 let n_flags = flags.to_linkat_posix();
605
606 if flag_set(n_flags, libc::AT_SYMLINK_FOLLOW) != should_follow {
607 // this should never happen, but adding an extra dynamic check let me
608 // avoid reasoning about bitwise operation math (which prusti does not support well)
609 // in the proof
610 return Err(Einval);
611 }
612
613 let res = trace_linkat(
614 ctx,
615 old_fd,
616 old_host_pathname,
617 new_fd,
618 new_host_pathname,
619 n_flags,
620 )?;
621 Ok(())
622}
623
624// https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#path_readlink
625// modifies: mem

Calls 5

flag_setFunction · 0.85
trace_linkatFunction · 0.85
should_followMethod · 0.80
translate_pathMethod · 0.80
to_linkat_posixMethod · 0.80

Tested by

no test coverage detected