From c0d068229be72078ab75890939d2c1c3ee1ad9f2 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 6 May 2025 17:43:49 +0200 Subject: [PATCH] xfree86: common: extra safety checks for NULL pointers Even though it's unlikely ever getting it, still safer to have some extra checks / asserts than unexpected segfault. Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xfree86/common/xf86Configure.c | 16 ++++++++-------- hw/xfree86/common/xf86Events.c | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index b1fc83b14..6242cad50 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -341,9 +341,8 @@ configureLayoutSection(void) ptr->lay_identifier = "X.org Configured"; { - XF86ConfInputrefPtr iptr; - - iptr = malloc(sizeof(XF86ConfInputrefRec)); + XF86ConfInputrefPtr iptr = calloc(1, sizeof(XF86ConfInputrefRec)); + assert(iptr); iptr->list.next = NULL; iptr->iref_option_lst = NULL; iptr->iref_inputdev_str = XNFstrdup("Mouse0"); @@ -355,9 +354,8 @@ configureLayoutSection(void) } { - XF86ConfInputrefPtr iptr; - - iptr = malloc(sizeof(XF86ConfInputrefRec)); + XF86ConfInputrefPtr iptr = calloc(1, sizeof(XF86ConfInputrefRec)); + assert(iptr); iptr->list.next = NULL; iptr->iref_option_lst = NULL; iptr->iref_inputdev_str = XNFstrdup("Keyboard0"); @@ -369,10 +367,10 @@ configureLayoutSection(void) } for (scrnum = 0; scrnum < nDevToConfig; scrnum++) { - XF86ConfAdjacencyPtr aptr; char *tmp; - aptr = malloc(sizeof(XF86ConfAdjacencyRec)); + XF86ConfAdjacencyPtr aptr = calloc(1, sizeof(XF86ConfAdjacencyRec)); + assert(aptr); aptr->list.next = NULL; aptr->adj_x = 0; aptr->adj_y = 0; @@ -466,6 +464,7 @@ handle_detailed_input(struct detailed_monitor_section *det_mon, void *data) ptr->mon_modelname = realloc(ptr->mon_modelname, strlen((char *) (det_mon->section.name)) + 1); + assert(ptr->mon_modelname); strcpy(ptr->mon_modelname, (char *) (det_mon->section.name)); break; case DS_RANGES: @@ -655,6 +654,7 @@ DoConfigure(void) XF86ConfMonitorPtr monitor_ptr; XF86ConfScreenPtr screen_ptr; + assert(xf86config); device_ptr = configureDeviceSection(screennum); xf86config->conf_device_lst = (XF86ConfDevicePtr) xf86addListItem((glp) xf86config-> diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index 9583fce21..08c5a6127 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -616,7 +616,7 @@ removeInputHandler(IHPtr ih) p = InputHandlers; while (p && p->next != ih) p = p->next; - if (ih) + if (ih && p) p->next = ih->next; } free(ih);