diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-10-12 11:17:49 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-10-12 11:17:49 +0000 |
commit | d5e305944a9db25f57b252cc9f56c18311e68481 (patch) | |
tree | 5f76ea7623209d379a9ea34bfa943ef86af2032a /util-linux/volume_id/luks.c | |
parent | cdd1f732bc5b8447dd12b59613663b7d08fce20b (diff) | |
download | busybox-w32-d5e305944a9db25f57b252cc9f56c18311e68481.tar.gz busybox-w32-d5e305944a9db25f57b252cc9f56c18311e68481.tar.bz2 busybox-w32-d5e305944a9db25f57b252cc9f56c18311e68481.zip |
findfs: fix LUKS and FAT detection routines; do not exit if corrupted
FAT fs makes us try to seek past volume
function old new delta
volume_id_get_buffer 301 327 +26
volume_id_probe_luks 79 82 +3
get_attr_volume_id 73 65 -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 29/-8) Total: 21 bytes
Diffstat (limited to 'util-linux/volume_id/luks.c')
-rw-r--r-- | util-linux/volume_id/luks.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/util-linux/volume_id/luks.c b/util-linux/volume_id/luks.c index 51dda4e79..b0f0f5b21 100644 --- a/util-linux/volume_id/luks.c +++ b/util-linux/volume_id/luks.c | |||
@@ -20,20 +20,16 @@ | |||
20 | 20 | ||
21 | #include "volume_id_internal.h" | 21 | #include "volume_id_internal.h" |
22 | 22 | ||
23 | #define SECTOR_SHIFT 9 | 23 | #define LUKS_MAGIC_L 6 |
24 | #define SECTOR_SIZE (1 << SECTOR_SHIFT) | 24 | #define UUID_STRING_L 40 |
25 | 25 | #define LUKS_CIPHERNAME_L 32 | |
26 | #define LUKS_CIPHERNAME_L 32 | 26 | #define LUKS_CIPHERMODE_L 32 |
27 | #define LUKS_CIPHERMODE_L 32 | 27 | #define LUKS_HASHSPEC_L 32 |
28 | #define LUKS_HASHSPEC_L 32 | 28 | #define LUKS_DIGESTSIZE 20 |
29 | #define LUKS_DIGESTSIZE 20 | 29 | #define LUKS_SALTSIZE 32 |
30 | #define LUKS_SALTSIZE 32 | 30 | #define LUKS_NUMKEYS 8 |
31 | #define LUKS_NUMKEYS 8 | ||
32 | 31 | ||
33 | static const uint8_t LUKS_MAGIC[] = { 'L','U','K','S', 0xba, 0xbe }; | 32 | static const uint8_t LUKS_MAGIC[] = { 'L','U','K','S', 0xba, 0xbe }; |
34 | #define LUKS_MAGIC_L 6 | ||
35 | #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1) | ||
36 | #define UUID_STRING_L 40 | ||
37 | 33 | ||
38 | struct luks_phdr { | 34 | struct luks_phdr { |
39 | uint8_t magic[LUKS_MAGIC_L]; | 35 | uint8_t magic[LUKS_MAGIC_L]; |
@@ -56,11 +52,39 @@ struct luks_phdr { | |||
56 | } keyblock[LUKS_NUMKEYS]; | 52 | } keyblock[LUKS_NUMKEYS]; |
57 | }; | 53 | }; |
58 | 54 | ||
55 | enum { | ||
56 | EXPECTED_SIZE_luks_phdr = 0 | ||
57 | + 1 * LUKS_MAGIC_L | ||
58 | + 2 | ||
59 | + 1 * LUKS_CIPHERNAME_L | ||
60 | + 1 * LUKS_CIPHERMODE_L | ||
61 | + 1 * LUKS_HASHSPEC_L | ||
62 | + 4 | ||
63 | + 4 | ||
64 | + 1 * LUKS_DIGESTSIZE | ||
65 | + 1 * LUKS_SALTSIZE | ||
66 | + 4 | ||
67 | + 1 * UUID_STRING_L | ||
68 | + LUKS_NUMKEYS * (0 | ||
69 | + 4 | ||
70 | + 4 | ||
71 | + 1 * LUKS_SALTSIZE | ||
72 | + 4 | ||
73 | + 4 | ||
74 | ) | ||
75 | }; | ||
76 | |||
77 | struct BUG_bad_size_luks_phdr { | ||
78 | char BUG_bad_size_luks_phdr[ | ||
79 | sizeof(struct luks_phdr) == EXPECTED_SIZE_luks_phdr ? | ||
80 | 1 : -1]; | ||
81 | }; | ||
82 | |||
59 | int volume_id_probe_luks(struct volume_id *id, uint64_t off) | 83 | int volume_id_probe_luks(struct volume_id *id, uint64_t off) |
60 | { | 84 | { |
61 | struct luks_phdr *header; | 85 | struct luks_phdr *header; |
62 | 86 | ||
63 | header = volume_id_get_buffer(id, off, LUKS_PHDR_SIZE); | 87 | header = volume_id_get_buffer(id, off, sizeof(*header)); |
64 | if (header == NULL) | 88 | if (header == NULL) |
65 | return -1; | 89 | return -1; |
66 | 90 | ||