diff options
author | Denis Vlasenko | 2008-10-12 11:17:49 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-10-12 11:17:49 +0000 |
commit | d5e305944a9db25f57b252cc9f56c18311e68481 (patch) | |
tree | 5f76ea7623209d379a9ea34bfa943ef86af2032a /util-linux/volume_id/luks.c | |
parent | cdd1f732bc5b8447dd12b59613663b7d08fce20b (diff) | |
download | busybox-d5e305944a9db25f57b252cc9f56c18311e68481.zip busybox-d5e305944a9db25f57b252cc9f56c18311e68481.tar.gz |
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 51dda4e..b0f0f5b 100644 --- a/util-linux/volume_id/luks.c +++ b/util-linux/volume_id/luks.c @@ -20,20 +20,16 @@ #include "volume_id_internal.h" -#define SECTOR_SHIFT 9 -#define SECTOR_SIZE (1 << SECTOR_SHIFT) - -#define LUKS_CIPHERNAME_L 32 -#define LUKS_CIPHERMODE_L 32 -#define LUKS_HASHSPEC_L 32 -#define LUKS_DIGESTSIZE 20 -#define LUKS_SALTSIZE 32 -#define LUKS_NUMKEYS 8 +#define LUKS_MAGIC_L 6 +#define UUID_STRING_L 40 +#define LUKS_CIPHERNAME_L 32 +#define LUKS_CIPHERMODE_L 32 +#define LUKS_HASHSPEC_L 32 +#define LUKS_DIGESTSIZE 20 +#define LUKS_SALTSIZE 32 +#define LUKS_NUMKEYS 8 static const uint8_t LUKS_MAGIC[] = { 'L','U','K','S', 0xba, 0xbe }; -#define LUKS_MAGIC_L 6 -#define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1) -#define UUID_STRING_L 40 struct luks_phdr { uint8_t magic[LUKS_MAGIC_L]; @@ -56,11 +52,39 @@ struct luks_phdr { } keyblock[LUKS_NUMKEYS]; }; +enum { + EXPECTED_SIZE_luks_phdr = 0 + + 1 * LUKS_MAGIC_L + + 2 + + 1 * LUKS_CIPHERNAME_L + + 1 * LUKS_CIPHERMODE_L + + 1 * LUKS_HASHSPEC_L + + 4 + + 4 + + 1 * LUKS_DIGESTSIZE + + 1 * LUKS_SALTSIZE + + 4 + + 1 * UUID_STRING_L + + LUKS_NUMKEYS * (0 + + 4 + + 4 + + 1 * LUKS_SALTSIZE + + 4 + + 4 + ) +}; + +struct BUG_bad_size_luks_phdr { + char BUG_bad_size_luks_phdr[ + sizeof(struct luks_phdr) == EXPECTED_SIZE_luks_phdr ? + 1 : -1]; +}; + int volume_id_probe_luks(struct volume_id *id, uint64_t off) { struct luks_phdr *header; - header = volume_id_get_buffer(id, off, LUKS_PHDR_SIZE); + header = volume_id_get_buffer(id, off, sizeof(*header)); if (header == NULL) return -1; |