summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-09-23 22:17:39 +0200
committerLudovic Courtès <ludo@gnu.org>2019-09-23 23:41:19 +0200
commit24ab804ce11fe12ff49cd144a3d9c4bfcf55b41c (patch)
treefa0c67df4051d433e02a6b910717d44ec9bfda41
parent7abd5997f41fec38ea1daa9099a9693062f10dbc (diff)
gexp: Catch and report non-self-quoting gexp inputs.
Previously we would, for example, generate build scripts in the store; when trying to run them, we'd get a 'read' error due to the presence of #<foo> syntax in there. * guix/gexp.scm (gexp->sexp)[self-quoting?]: New procedure. [reference->sexp]: Check whether the argument in a <gexp-input> box is self-quoting. Raise a '&gexp-input-error' condition if it's not. * tests/gexp.scm ("lower-gexp, non-self-quoting input"): New test.
-rw-r--r--guix/gexp.scm13
-rw-r--r--tests/gexp.scm7
2 files changed, 19 insertions, 1 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm
index 45cd5869f70..0d0b661c656 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -1005,6 +1005,15 @@ references; otherwise, return only non-native references."
1005 (target (%current-target-system))) 1005 (target (%current-target-system)))
1006 "Return (monadically) the sexp corresponding to EXP for the given OUTPUT, 1006 "Return (monadically) the sexp corresponding to EXP for the given OUTPUT,
1007and in the current monad setting (system type, etc.)" 1007and in the current monad setting (system type, etc.)"
1008 (define (self-quoting? x)
1009 (letrec-syntax ((one-of (syntax-rules ()
1010 ((_) #f)
1011 ((_ pred rest ...)
1012 (or (pred x)
1013 (one-of rest ...))))))
1014 (one-of symbol? string? keyword? pair? null? array?
1015 number? boolean?)))
1016
1008 (define* (reference->sexp ref #:optional native?) 1017 (define* (reference->sexp ref #:optional native?)
1009 (with-monad %store-monad 1018 (with-monad %store-monad
1010 (match ref 1019 (match ref
@@ -1034,8 +1043,10 @@ and in the current monad setting (system type, etc.)"
1034 #:target target))) 1043 #:target target)))
1035 ;; OBJ must be either a derivation or a store file name. 1044 ;; OBJ must be either a derivation or a store file name.
1036 (return (expand thing obj output))))) 1045 (return (expand thing obj output)))))
1037 (($ <gexp-input> x) 1046 (($ <gexp-input> (? self-quoting? x))
1038 (return x)) 1047 (return x))
1048 (($ <gexp-input> x)
1049 (raise (condition (&gexp-input-error (input x)))))
1039 (x 1050 (x
1040 (return x))))) 1051 (return x)))))
1041 1052
diff --git a/tests/gexp.scm b/tests/gexp.scm
index 5c013d838d9..50d09486599 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -871,6 +871,13 @@
871 (eq? (derivation-input-derivation (lowered-gexp-guile lexp)) 871 (eq? (derivation-input-derivation (lowered-gexp-guile lexp))
872 (%guile-for-build))))))) 872 (%guile-for-build)))))))
873 873
874(test-eq "lower-gexp, non-self-quoting input"
875 +
876 (guard (c ((gexp-input-error? c)
877 (gexp-error-invalid-input c)))
878 (run-with-store %store
879 (lower-gexp #~(foo #$+)))))
880
874(test-assertm "gexp->derivation #:references-graphs" 881(test-assertm "gexp->derivation #:references-graphs"
875 (mlet* %store-monad 882 (mlet* %store-monad
876 ((one (text-file "one" (random-text))) 883 ((one (text-file "one" (random-text)))