Skip to content

Commit

Permalink
Don't alter-var-root -- leave that to the user if they want it bad en…
Browse files Browse the repository at this point in the history
…ough. It causes bugs that make no sense.
  • Loading branch information
Raynes committed Oct 19, 2011
1 parent 5a0e143 commit 5a4e121
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/clojail/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
(.getName p)
"\")"))))

(def ^{:private true} separate-dynamic
(partial (juxt filter remove) #(-> % first .isDynamic)))

(defn sandbox*
"This function creates a sandbox function that takes a tester. A tester can either be a plain set of symbols,
in which case it'll be treated as a blacklist. Otherwise, you can provide a map of :whitelist and
Expand Down Expand Up @@ -149,7 +152,6 @@
(binding [*ns* (create-ns namespace)
*read-eval* false]
(refer 'clojure.core)
(when init (eval init))
(let [bindings (or bindings {})
code
`(do
Expand All @@ -172,10 +174,9 @@
(.getPackage ~'obj-class#)])]
(throw (SecurityException. (str "You tripped the alarm! " ~'bad# " is bad!")))
(. ~object# ~method# ~@args#))))
~(doseq [[var new-var] bindings]
(alter-var-root var (constantly new-var)))
~(ensafen code))]
(jvm-sandbox #(eval code) context))))
(when init (eval init))
(with-bindings bindings (jvm-sandbox #(eval code) context)))))
timeout :ms transform)))))

(defn sandbox
Expand Down
2 changes: 1 addition & 1 deletion test/clojail/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
(is (= [0 0] (sb '(map #(.length %) ["" ""])))))

(deftest binding-test
(is (= 2 (sb '(#'inc 2) {#'inc identity}))))
(is (= 2 (sb '(#'*out* 2) {#'*out* identity}))))

(deftest macroexpand-test
(is (= 'let (sb '(first '(let [x 1] x)))))
Expand Down

0 comments on commit 5a4e121

Please sign in to comment.