summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2022-08-30 19:18:26 +0200
committerMathieu Othacehe <othacehe@gnu.org>2022-08-30 19:29:58 +0200
commitbce7a28a0a38da41fca91cfdbf7ae0fe14833f2a (patch)
tree88f0690ecca34c8d128e880535576f1d6441c379 /gnu
parent192b7d0c0b0958d6c87df6084a644e0c7eca2ec0 (diff)
image: Perform more sanitizing.
* gnu/image.scm (validate-size, validate-partition-offset, validate-partition-flags): New macros. (<partition>)[size, offset, flags]: Sanitize those fields using the above procedures respectively.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/image.scm72
1 files changed, 62 insertions, 10 deletions
diff --git a/gnu/image.scm b/gnu/image.scm
index 486c02aadc1..21ac70e56aa 100644
--- a/gnu/image.scm
+++ b/gnu/image.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> 2;;; Copyright © 2020, 2022 Mathieu Othacehe <othacehe@gnu.org>
3;;; 3;;;
4;;; This file is part of GNU Guix. 4;;; This file is part of GNU Guix.
5;;; 5;;;
@@ -21,6 +21,7 @@
21 #:use-module (guix records) 21 #:use-module (guix records)
22 #:use-module (guix diagnostics) 22 #:use-module (guix diagnostics)
23 #:use-module (guix i18n) 23 #:use-module (guix i18n)
24 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-34) 25 #:use-module (srfi srfi-34)
25 #:use-module (srfi srfi-35) 26 #:use-module (srfi srfi-35)
26 #:export (partition 27 #:export (partition
@@ -60,21 +61,71 @@
60 61
61 62
62;;; 63;;;
64;;; Sanitizers.
65;;;
66
67(define-with-syntax-properties (validate-size (value properties))
68 (unless (and value
69 (or (eq? value 'guess) (integer? value)))
70 (raise
71 (make-compound-condition
72 (condition
73 (&error-location
74 (location (source-properties->location properties))))
75 (formatted-message
76 (G_ "size (~a) can only be 'guess or a numeric expression ~%")
77 value 'field))))
78 value)
79
80
81;;;
63;;; Partition record. 82;;; Partition record.
64;;; 83;;;
65 84
85(define-with-syntax-properties (validate-partition-offset (value properties))
86 (unless (and value (integer? value))
87 (raise
88 (make-compound-condition
89 (condition
90 (&error-location
91 (location (source-properties->location properties))))
92 (formatted-message
93 (G_ "the partition offset (~a) can only be a \
94numeric expression ~%") value 'field))))
95 value)
96
97(define-with-syntax-properties (validate-partition-flags (value properties))
98 (let ((bad-flags (lset-difference eq? value '(boot esp))))
99 (unless (and (list? value) (null? bad-flags))
100 (raise
101 (make-compound-condition
102 (condition
103 (&error-location
104 (location (source-properties->location properties))))
105 (formatted-message
106 (G_ "unsupported partition flag(s): ~a ~%") bad-flags)))))
107 value)
108
66(define-record-type* <partition> partition make-partition 109(define-record-type* <partition> partition make-partition
67 partition? 110 partition?
68 (device partition-device (default #f)) 111 (device partition-device (default #f))
69 (size partition-size) 112 (size partition-size ;size in bytes as integer or 'guess
70 (offset partition-offset (default 0)) 113 (sanitize validate-size))
71 (file-system partition-file-system (default "ext4")) 114 (offset partition-offset
115 (default 0) ;offset in bytes as integer
116 (sanitize validate-partition-offset))
117 (file-system partition-file-system
118 (default "ext4")) ;string
72 (file-system-options partition-file-system-options 119 (file-system-options partition-file-system-options
73 (default '())) 120 (default '())) ;list of strings
74 (label partition-label (default #f)) 121 (label partition-label) ;string
75 (uuid partition-uuid (default #f)) 122 (uuid partition-uuid
76 (flags partition-flags (default '())) 123 (default #f)) ;<uuid>
77 (initializer partition-initializer (default #f))) ;gexp | #f 124 (flags partition-flags
125 (default '()) ;list of symbols
126 (sanitize validate-partition-flags))
127 (initializer partition-initializer
128 (default #f))) ;gexp | #f
78 129
79 130
80;;; 131;;;
@@ -109,7 +160,8 @@ that is not in SET, mentioning FIELD in the error message."
109 (platform image-platform ;<platform> 160 (platform image-platform ;<platform>
110 (default #f)) 161 (default #f))
111 (size image-size ;size in bytes as integer 162 (size image-size ;size in bytes as integer
112 (default 'guess)) 163 (default 'guess)
164 (sanitize validate-size))
113 (operating-system image-operating-system ;<operating-system> 165 (operating-system image-operating-system ;<operating-system>
114 (default #f)) 166 (default #f))
115 (partition-table-type image-partition-table-type ; 'mbr or 'gpt 167 (partition-table-type image-partition-table-type ; 'mbr or 'gpt