Arc Forumnew | comments | leaders | submitlogin
3 points by waterhouse 4974 days ago | link | parent

The sandbox library seems to work fairly well. Using the awesome quasiquote bug/feature that lets you drop to Scheme[0], I was able to evaluate (current-directory) --> "/root/arc/arc3.1/" and (version) --> "4.1.5", but the functions 'directory-list (like "ls"), 'open-output-file, and 'system don't do anything. Also, (current-directory <something>), which would change the current directory, doesn't do anything. That's probably somewhat reassuring to know, security-wise. (Someone has to try these things out, and it may as well be me, who intends to do no harm, before it's someone else, who might feel mischievous.)

By the way, an end-user can emulate stdout by doing something like this:

  (def eval-w/stdout (expr)
    (tostring:let result nil
      (let output (tostring (= result (eval expr)))
        (unless (empty output)
          (prn "output: " output))
        (write result))))
In action: (for some reason, when I copied this, it had a bunch of extra spaces)

  arc> (eval-w/stdout '(time (reduce + (n-of 1000 rand.100))))
  output: time: 339 msec.
  
  49840
[0]http://arclanguage.org/item?id=11838


2 points by evanrmurphy 4973 days ago | link

Try Arc saw two updates today:

1. stdout now displays properly.

  arc> (pr "hello")
  hello"hello"
@waterhouse thank you for your eval-w/stdout function. I tried about twelve variations on the idea but ended up back at exactly the definition you gave. Even one cosmetic change that I was sure would be an improvement turned out to make it harder to read (at least in my opinion):

   (def eval-w/stdout (expr)
  -  (tostring:let result nil
  -    (let output (tostring (= result (eval expr)))
  +  (tostring:withs (result nil
  +                   output (tostring (= result (eval expr))))
         (unless (empty output)
           (prn "output: " output))
  -      (write result))))
  +      (write result)))
2. strings.arc, pprint.arc and html.arc are now all included in the sandbox:

  arc> (plural 2 "dog")
  "2 dogs"

  ; not indenting properly
  arc> (ppr:macex1 '(accum a (each  x '(1 2 3) (a x))))
  (withs (gs954 nil
  a
  (fn (_) (push _ gs954)))
  (each x (quote (1 2 3)) (a x))
  (rev gs954))t

  arc> (tag strong (link  "Arc Forum" "http://arclanguage.org"))
  <strong><a href="http://arclanguage.org">Arc Forum</a></strong>"</strong>"
At least for the moment I'm not including srv.arc, app.arc, code.arc and prompt.arc. Most of their functions couldn't be used in the sandbox anyway, and I can conserve resources (i.e. loading them in for each new user) by leaving them out.

-----

2 points by evanrmurphy 4972 days ago | link

I added support for multi-line entry:

  arc> (def average (x y)
  >      (prn "my arguments were:  " (list x y))
  >      (/ (+ x y) 2))
  #<procedure: average>
  arc> (average 100 200)
  my arguments were: (100 200)
  150
It simply checks for balanced parens. I just realized I neglected to check for balanced #\[ and #\] though, so for the moment your square-bracketed functions must be on one line.

-----

2 points by evanrmurphy 4974 days ago | link

Using the awesome quasiquote bug/feature that lets you drop to Scheme...

That is an awesome bug/feature.

To be sure, what you get at that repl isn't pure arc3.1 (at least for now it's not). It's arc3.1 plus anarki's $ minus libs.arc. So since it has $, you can drop to scheme without even exploiting rocketnia's discovery. You just can't do much harm there (at least, you're not supposed to be able to do much harm there, and you just helped me gain a bit of confidence about that).

It does concern me that you're able to see the current directory and version, but I guess as long as you're not able to change anything on the system it might be ok.

(Someone has to try these things out, and it may as well be me, who intends to do no harm, before it's someone else, who might feel mischievous.)

I completely agree. Thank you for trying to break it and reporting your results.

-----