mirror of
https://github.com/tailix/libkernaux.git
synced 2024-11-13 11:04:27 -05:00
Validate that Multiboot 2 memory map tag entry size is mul of 8
This commit is contained in:
parent
f8079ca66c
commit
96d9f1e65e
2 changed files with 67 additions and 0 deletions
|
@ -229,6 +229,7 @@ unsigned char KernAux_Multiboot2_Tag_MemoryMap_is_valid(
|
|||
return (
|
||||
tag->base.type == KERNAUX_MULTIBOOT2_TAGTYPE_MEMORY_MAP &&
|
||||
tag->base.size >= 16 &&
|
||||
tag->entry_size % 8 == 0 &&
|
||||
(tag->base.size - 16) % tag->entry_size == 0
|
||||
);
|
||||
}
|
||||
|
|
|
@ -421,6 +421,44 @@ static const struct {
|
|||
},
|
||||
};
|
||||
|
||||
static const struct KernAux_Multiboot2_Tag_MemoryMap
|
||||
tag_memory_map_with_empty_data_invalid_entry_size_not_mul8 = {
|
||||
.base = {
|
||||
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MEMORY_MAP,
|
||||
.size = 16,
|
||||
},
|
||||
.entry_size = 9,
|
||||
.entry_version = 0,
|
||||
};
|
||||
|
||||
static const struct {
|
||||
struct KernAux_Multiboot2_Tag_MemoryMap tag;
|
||||
unsigned char data[9 * 2];
|
||||
} tag_memory_map_with_some_small_data_items_invalid_entry_size_not_mul8 = {
|
||||
.tag = {
|
||||
.base = {
|
||||
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MEMORY_MAP,
|
||||
.size = 16 + 9 * 2,
|
||||
},
|
||||
.entry_size = 9,
|
||||
.entry_version = 123,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct {
|
||||
struct KernAux_Multiboot2_Tag_MemoryMap tag;
|
||||
unsigned char data[63 * 2];
|
||||
} tag_memory_map_with_some_large_data_items_invalid_entry_size_not_mul8 = {
|
||||
.tag = {
|
||||
.base = {
|
||||
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MEMORY_MAP,
|
||||
.size = 16 + 63 * 2,
|
||||
},
|
||||
.entry_size = 63,
|
||||
.entry_version = 123,
|
||||
},
|
||||
};
|
||||
|
||||
/***************
|
||||
* Tag_VBEInfo *
|
||||
***************/
|
||||
|
@ -900,6 +938,20 @@ int main()
|
|||
&tag_memory_map_with_some_large_data_items_invalid_size.tag.base
|
||||
));
|
||||
|
||||
assert(!KernAux_Multiboot2_TagBase_is_valid(
|
||||
&tag_memory_map_with_empty_data_invalid_entry_size_not_mul8.base
|
||||
));
|
||||
|
||||
assert(!KernAux_Multiboot2_TagBase_is_valid(
|
||||
&tag_memory_map_with_some_small_data_items_invalid_entry_size_not_mul8
|
||||
.tag.base
|
||||
));
|
||||
|
||||
assert(!KernAux_Multiboot2_TagBase_is_valid(
|
||||
&tag_memory_map_with_some_large_data_items_invalid_entry_size_not_mul8
|
||||
.tag.base
|
||||
));
|
||||
|
||||
assert(KernAux_Multiboot2_TagBase_is_valid(
|
||||
&tag_vbe_info_valid.base
|
||||
));
|
||||
|
@ -1038,6 +1090,20 @@ int main()
|
|||
&tag_memory_map_with_some_large_data_items_invalid_size.tag
|
||||
));
|
||||
|
||||
assert(!KernAux_Multiboot2_Tag_MemoryMap_is_valid(
|
||||
&tag_memory_map_with_empty_data_invalid_entry_size_not_mul8
|
||||
));
|
||||
|
||||
assert(!KernAux_Multiboot2_Tag_MemoryMap_is_valid(
|
||||
&tag_memory_map_with_some_small_data_items_invalid_entry_size_not_mul8
|
||||
.tag
|
||||
));
|
||||
|
||||
assert(!KernAux_Multiboot2_Tag_MemoryMap_is_valid(
|
||||
&tag_memory_map_with_some_large_data_items_invalid_entry_size_not_mul8
|
||||
.tag
|
||||
));
|
||||
|
||||
// Tag_VBEInfo
|
||||
|
||||
assert(KernAux_Multiboot2_Tag_VBEInfo_is_valid(
|
||||
|
|
Loading…
Reference in a new issue