term: Better ensure term is not accessed when NULL

This commit is contained in:
mintsuki 2022-10-05 15:01:01 +02:00
parent ec9d384bf2
commit ac34ec411f
6 changed files with 29 additions and 14 deletions

View File

@ -253,6 +253,11 @@ static void text_deinit(struct term_context *_ctx, void (*_free)(void *, size_t)
static struct textmode_context term_local_struct;
void vga_textmode_init(bool managed) {
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
if (quiet) {
return;
}
@ -265,11 +270,6 @@ void vga_textmode_init(bool managed) {
current_video_mode = 0x3;
}
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
struct textmode_context *ctx = &term_local_struct;
term = &term_local_struct.term;

View File

@ -538,6 +538,10 @@ static char *last_config = NULL;
bool gterm_init(char *config, size_t width, size_t height) {
if (quiet) {
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
return false;
}

View File

@ -216,8 +216,10 @@ noreturn void efi_chainload_file(char *config, struct file_handle *image) {
pmm_free(_ptr, image->size);
fclose(image);
term->deinit(term, pmm_free);
term = NULL;
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
size_t req_width = 0, req_height = 0, req_bpp = 0;

View File

@ -495,8 +495,10 @@ noreturn void linux_load(char *config, char *cmdline) {
// Video
///////////////////////////////////////
term->deinit(term, pmm_free);
term = NULL;
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
struct screen_info *screen_info = &boot_params->screen_info;
@ -522,7 +524,7 @@ noreturn void linux_load(char *config, char *cmdline) {
#endif
if (!fb_init(&fbinfo, req_width, req_height, req_bpp)) {
#if defined (UEFI)
panic(true, "linux: Unable to set video mode");
goto no_fb;
#elif defined (BIOS)
set_textmode:;
vga_textmode_init(false);
@ -562,6 +564,9 @@ set_textmode:;
}
}
#if defined (UEFI)
no_fb:;
#endif
struct edid_info_struct *edid_info = get_edid_info();
if (edid_info != NULL) {

View File

@ -302,8 +302,10 @@ noreturn void multiboot1_load(char *config, char *cmdline) {
multiboot1_info->bootloader_name = (uint32_t)(size_t)lowmem_bootname - mb1_info_slide;
multiboot1_info->flags |= (1 << 9);
term->deinit(term, pmm_free);
term = NULL;
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
if (header.flags & (1 << 2)) {
size_t req_width = header.fb_width;

View File

@ -505,8 +505,10 @@ noreturn void multiboot2_load(char *config, char* cmdline) {
tag->common.type = MULTIBOOT_TAG_TYPE_FRAMEBUFFER;
tag->common.size = sizeof(struct multiboot_tag_framebuffer);
term->deinit(term, pmm_free);
term = NULL;
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
if (fbtag) {
size_t req_width = fbtag->width;