1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00

Write code

This commit is contained in:
Alex Kotov 2022-01-13 19:32:19 +05:00
parent c8d010fb19
commit 2c3714b99c
2 changed files with 56 additions and 6 deletions

View file

@ -5,12 +5,56 @@
#include <kernaux/multiboot2.h> #include <kernaux/multiboot2.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
bool KernAux_Multiboot2_Header_is_valid( bool KernAux_Multiboot2_Header_is_valid(
const struct KernAux_Multiboot2_Header *const multiboot2_header const struct KernAux_Multiboot2_Header *const multiboot2_header
) { ) {
// TODO: write this if (multiboot2_header->total_size <
sizeof(struct KernAux_Multiboot2_Header) +
sizeof(struct KernAux_Multiboot2_HTag_None))
{
return false; return false;
}
const struct KernAux_Multiboot2_HTagBase *tag_base =
(struct KernAux_Multiboot2_HTagBase*)
KERNAUX_MULTIBOOT2_DATA(multiboot2_header);
const struct KernAux_Multiboot2_HTagBase *none_tag_base = NULL;
while (tag_base <
(struct KernAux_Multiboot2_HTagBase*)
((uint8_t*)multiboot2_header + multiboot2_header->total_size))
{
if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return false;
if (tag_base->type == KERNAUX_MULTIBOOT2_HTAG_NONE &&
none_tag_base == NULL
) {
none_tag_base = tag_base;
}
tag_base = KERNAUX_MULTIBOOT2_HTAG_NEXT(tag_base);
}
if (tag_base !=
(struct KernAux_Multiboot2_HTagBase*)
((uint8_t*)multiboot2_header + multiboot2_header->total_size))
{
return false;
}
if (none_tag_base !=
(struct KernAux_Multiboot2_HTagBase*)
((uint8_t*)tag_base -
sizeof(struct KernAux_Multiboot2_HTag_None)))
{
return false;
}
return true;
} }
bool KernAux_Multiboot2_HTagBase_is_valid( bool KernAux_Multiboot2_HTagBase_is_valid(

View file

@ -6,11 +6,17 @@
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
bool KernAux_Multiboot2_Info_is_valid( bool KernAux_Multiboot2_Info_is_valid(
const struct KernAux_Multiboot2_Info *const multiboot2_info const struct KernAux_Multiboot2_Info *const multiboot2_info
) { ) {
if (multiboot2_info->total_size <= 8) return false; if (multiboot2_info->total_size <
sizeof(struct KernAux_Multiboot2_Info) +
sizeof(struct KernAux_Multiboot2_ITag_None))
{
return false;
}
const struct KernAux_Multiboot2_ITagBase *tag_base = const struct KernAux_Multiboot2_ITagBase *tag_base =
(struct KernAux_Multiboot2_ITagBase*) (struct KernAux_Multiboot2_ITagBase*)
@ -20,7 +26,7 @@ bool KernAux_Multiboot2_Info_is_valid(
while (tag_base < while (tag_base <
(struct KernAux_Multiboot2_ITagBase*) (struct KernAux_Multiboot2_ITagBase*)
((unsigned char*)multiboot2_info + multiboot2_info->total_size)) ((uint8_t*)multiboot2_info + multiboot2_info->total_size))
{ {
if (!KernAux_Multiboot2_ITagBase_is_valid(tag_base)) return false; if (!KernAux_Multiboot2_ITagBase_is_valid(tag_base)) return false;
@ -35,14 +41,14 @@ bool KernAux_Multiboot2_Info_is_valid(
if (tag_base != if (tag_base !=
(struct KernAux_Multiboot2_ITagBase*) (struct KernAux_Multiboot2_ITagBase*)
((unsigned char*)multiboot2_info + multiboot2_info->total_size)) ((uint8_t*)multiboot2_info + multiboot2_info->total_size))
{ {
return false; return false;
} }
if (none_tag_base != if (none_tag_base !=
(struct KernAux_Multiboot2_ITagBase*) (struct KernAux_Multiboot2_ITagBase*)
((unsigned char*)tag_base - ((uint8_t*)tag_base -
sizeof(struct KernAux_Multiboot2_ITag_None))) sizeof(struct KernAux_Multiboot2_ITag_None)))
{ {
return false; return false;