提交 fa7ea87a 编写于 作者: T Timo Warns 提交者: Linus Torvalds

fs/partitions: Validate map_count in Mac partition tables

Validate number of blocks in map and remove redundant variable.
Signed-off-by: NTimo Warns <warns@pre-sense.de>
Cc: stable@kernel.org
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 ee715087
...@@ -29,10 +29,9 @@ static inline void mac_fix_string(char *stg, int len) ...@@ -29,10 +29,9 @@ static inline void mac_fix_string(char *stg, int len)
int mac_partition(struct parsed_partitions *state) int mac_partition(struct parsed_partitions *state)
{ {
int slot = 1;
Sector sect; Sector sect;
unsigned char *data; unsigned char *data;
int blk, blocks_in_map; int slot, blocks_in_map;
unsigned secsize; unsigned secsize;
#ifdef CONFIG_PPC_PMAC #ifdef CONFIG_PPC_PMAC
int found_root = 0; int found_root = 0;
...@@ -59,10 +58,14 @@ int mac_partition(struct parsed_partitions *state) ...@@ -59,10 +58,14 @@ int mac_partition(struct parsed_partitions *state)
put_dev_sector(sect); put_dev_sector(sect);
return 0; /* not a MacOS disk */ return 0; /* not a MacOS disk */
} }
strlcat(state->pp_buf, " [mac]", PAGE_SIZE);
blocks_in_map = be32_to_cpu(part->map_count); blocks_in_map = be32_to_cpu(part->map_count);
for (blk = 1; blk <= blocks_in_map; ++blk) { if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
int pos = blk * secsize; put_dev_sector(sect);
return 0;
}
strlcat(state->pp_buf, " [mac]", PAGE_SIZE);
for (slot = 1; slot <= blocks_in_map; ++slot) {
int pos = slot * secsize;
put_dev_sector(sect); put_dev_sector(sect);
data = read_part_sector(state, pos/512, &sect); data = read_part_sector(state, pos/512, &sect);
if (!data) if (!data)
...@@ -113,13 +116,11 @@ int mac_partition(struct parsed_partitions *state) ...@@ -113,13 +116,11 @@ int mac_partition(struct parsed_partitions *state)
} }
if (goodness > found_root_goodness) { if (goodness > found_root_goodness) {
found_root = blk; found_root = slot;
found_root_goodness = goodness; found_root_goodness = goodness;
} }
} }
#endif /* CONFIG_PPC_PMAC */ #endif /* CONFIG_PPC_PMAC */
++slot;
} }
#ifdef CONFIG_PPC_PMAC #ifdef CONFIG_PPC_PMAC
if (found_root_goodness) if (found_root_goodness)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册