jeroen/RAppArmor

Unexpected behavior when using eval.secure

Closed this issue · 3 comments

Since unix::eval_safe uses its parent.frame to evaluate expression. Using eval.secure vs unix::eval_safe is not the same.

See https://stackoverflow.com/questions/65236186/combining-r-plumber-and-rapparmor

eval.secure just pass all parameters to unix::eval_safe. The reason why eval.secure does not work is because eval_safe expects to find your variables in its parent.frame(), which in the case of eval.secure is an empty function body.

eval_safe use of parent.frame()

function (expr, tmp = tempfile("fork"), std_out = stdout(), std_err = stderr(), 
    timeout = 0, priority = NULL, uid = NULL, gid = NULL, rlimits = NULL, 
    profile = NULL, device = pdf) 
{
    orig_expr <- substitute(expr)
    out <- eval_fork(expr = tryCatch({
        if (length(priority)) 
            setpriority(priority)
        if (length(rlimits)) 
            set_rlimits(rlimits)
        if (length(gid)) 
            setgid(gid)
        if (length(uid)) 
            setuid(uid)
        if (length(profile)) 
            aa_change_profile(profile)
        if (length(device)) 
            options(device = device)
        graphics.off()
        options(menu.graphics = FALSE)
------> serialize(withVisible(eval(orig_expr, parent.frame())), 
            NULL)
    }, error = function(e) {
        old_class <- attr(e, "class")
        structure(e, class = c(old_class, "eval_fork_error"))
    }, finally = substitute(graphics.off())), tmp = tmp, timeout = timeout, 
        std_out = std_out, std_err = std_err)
    if (inherits(out, "eval_fork_error")) 
        base::stop(out)
    res <- unserialize(out)
    if (res$visible) 
        res$value
    else invisible(res$value)
}
# parent.frame() in eval_safe when using eval.secure
function (...) 
{
  # nothing here  
  unix::eval_safe(...)
}

# parent.frame() when using eval_safe directly
function(func){
  data <- cbind(rnorm(100),rnorm(100))
  # Your stuff is here
  unix::eval_safe(nrow(data), profile="r-user")
}

Can you suggest a fix?

I would set eval.secure to unix::eval_safe directly

Thanks!