diff options
author | Ludovic Courtès <ludo@gnu.org> | 2014-07-02 12:18:36 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2014-07-02 12:18:36 +0200 |
commit | d266b79332ff0a4b22967a1db01c805b7c82e092 (patch) | |
tree | efc1f80370a4af3275f6a893339c11d5e3985267 | |
parent | 0f28ee348778379bfa81094491b73479f1113f84 (diff) | |
download | gnu-guix-d266b79332ff0a4b22967a1db01c805b7c82e092.tar gnu-guix-d266b79332ff0a4b22967a1db01c805b7c82e092.tar.gz |
linux-initrd: Gracefully handle lack of or invalid ext2 superblocks.
Reported by David Thompson <dthompson2@worcester.edu>.
* guix/build/linux-initrd.scm (read-ext2-superblock): Add
'superblock-size' variable. Read with 'get-bytevector-n!' instead of
'getbytevector-n', and make sure we read exactly SUPERBLOCK-SIZE
bytes.
-rw-r--r-- | guix/build/linux-initrd.scm | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/guix/build/linux-initrd.scm b/guix/build/linux-initrd.scm index 627c55f865..7778c2ca97 100644 --- a/guix/build/linux-initrd.scm +++ b/guix/build/linux-initrd.scm @@ -116,14 +116,25 @@ if DEVICE does not contain an ext2 file system." ;; The magic bytes that identify an ext2 file system. #xef53) + (define superblock-size + ;; Size of the interesting part of an ext2 superblock. + 264) + + (define block + ;; The superblock contents. + (make-bytevector superblock-size)) + (call-with-input-file device (lambda (port) (seek port 1024 SEEK_SET) - (let* ((block (get-bytevector-n port 264)) - (magic (bytevector-u16-ref block %ext2-sblock-magic - %ext2-endianness))) - (and (= magic %ext2-magic) - block))))) + + ;; Note: work around <http://bugs.gnu.org/17466>. + (and (eqv? superblock-size (get-bytevector-n! port block 0 + superblock-size)) + (let ((magic (bytevector-u16-ref block %ext2-sblock-magic + %ext2-endianness))) + (and (= magic %ext2-magic) + block)))))) (define (ext2-superblock-uuid sblock) "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector." |