Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 36 additions and 12 deletions.
  1. +28 −12 sandbox.el
  2. +8 −0 spec/sandbox-spec.el
View
40 sandbox.el
@@ -53,8 +53,6 @@ We WON'T do this by default since this could lead to exploits if you
\(setq &rest (shell-command \"rm -rf /\")) in your .emacs."
)
-
-
;; main entry point is sandbox
;; sandbox takes an expression and makes sure it is okay to evaluate
@@ -167,16 +165,34 @@ redefunned, return true. "
(sandbox-readonly-check sandbox-fcn)
(let ((is-interactive-form (equal '(interactive) (first body))))
(if docp
- ;; puts the docstring in front
- `(defun sandbox-fcn args ,(first body) (sandbox--check-args ,@args) (sit-for 0) ,(cdr body))
- `(defun sandbox-fcn args (sandbox--check-args ,@args) (sit-for 0) body)))))
-
-(defun make-sandboxed-form)
-
-(defun sandbox-eval (form)
- (flet (((intern (concat sandbox-prefix "while")) (cond &rest body) (sandbox-while cond body))
- ((intern (concat sandbox-prefix "defun")) (fcn args &rest body ) (sandbox-defun fcn args body)))
- (eval (sandbox form))))
+ (cons 'defun
+ (cons sandbox-fcn
+ (cons args
+ (cons
+ (first body)
+ (cons
+ `(sandbox--check-args ,@args)
+ (cons
+ '(sit-for 0)
+ (cdr body)))))))
+ (cons 'defun
+ (cons sandbox-fcn
+ (cons args
+ (cons
+ `(sandbox--check-args ,@args)
+ (cons
+ '(sit-for 0)
+ body)))))))))
+
+(defun sandbox-eval (form &optional prefix)
+ (unless (or (stringp prefix) (eq nil prefix))
+ (error "Prefix should be a string"))
+ (let ((sandbox-prefix (or prefix sandbox-prefix))
+ (sandbox-defun-symbol (intern (concat sandbox-prefix "defun")))
+ (sandbox-while-symbol (intern (concat sandbox-prefix "while"))))
+ (flet ((sandbox-defun-symbol (fcn args &rest body ) (sandbox-defun fcn args body))
+ (sandbox-while-symbol (cond &rest body) (sandbox-while cond body)))
+ (eval (sandbox form)))))
(defvar sandbox-max-list-length 100)
View
8 spec/sandbox-spec.el
@@ -60,6 +60,14 @@
(let ((i 0))
(sandbox-while t (incf i))))))
+(describe "sandbox-eval"
+ (it "will eval defuns in a different namespace"
+ ;; todo: make a test scenario that will actually pass
+ (should (eq 3
+ (sandbox-eval
+ '(progn (defun testfn (one two) (+ one two))
+ (testfn 1 2)))))))
+
;; actual spec tests
(describe "sandbox"
(it "forbids the user from executing the bad stuff"

No commit comments for this range

Something went wrong with that request. Please try again.