[PATCH] Mini-OS: use BUG() instead of dereferencing NULL

Juergen Gross posted 1 patch 5 months, 2 weeks ago
Failed in applying to current master (apply log)
lib/xmalloc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] Mini-OS: use BUG() instead of dereferencing NULL
Posted by Juergen Gross 5 months, 2 weeks ago
There are some places using a dereference of NULL to cause a crash.

Use BUG() instead.

Reported-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 lib/xmalloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/xmalloc.c b/lib/xmalloc.c
index cc5db11e..2aa07138 100644
--- a/lib/xmalloc.c
+++ b/lib/xmalloc.c
@@ -219,7 +219,7 @@ void xfree(const void *p)
     if(((long)p & PAGE_MASK) != ((long)hdr & PAGE_MASK))
     {
         printk("Header should be on the same page\n");
-        *(int*)0=0;
+        BUG();
     }
 
     /* Merge with other free block, or put in list. */
@@ -255,7 +255,7 @@ void xfree(const void *p)
         if((((unsigned long)hdr) & (PAGE_SIZE-1)) != 0)
         {
             printk("Bug\n");
-            *(int*)0=0;
+            BUG();
         }
         free_page(hdr);
     }
-- 
2.35.3
Re: [PATCH] Mini-OS: use BUG() instead of dereferencing NULL
Posted by Andrew Cooper 5 months, 2 weeks ago
On 06/12/2023 11:30 am, Juergen Gross wrote:
> There are some places using a dereference of NULL to cause a crash.
>
> Use BUG() instead.
>
> Reported-by: Jan Beulich <jbeulich@suse.com>
> Signed-off-by: Juergen Gross <jgross@suse.com>

Wow...

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

> ---
>  lib/xmalloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/xmalloc.c b/lib/xmalloc.c
> index cc5db11e..2aa07138 100644
> --- a/lib/xmalloc.c
> +++ b/lib/xmalloc.c
> @@ -219,7 +219,7 @@ void xfree(const void *p)
>      if(((long)p & PAGE_MASK) != ((long)hdr & PAGE_MASK))
>      {
>          printk("Header should be on the same page\n");
> -        *(int*)0=0;
> +        BUG();
>      }
>  
>      /* Merge with other free block, or put in list. */
> @@ -255,7 +255,7 @@ void xfree(const void *p)
>          if((((unsigned long)hdr) & (PAGE_SIZE-1)) != 0)
>          {
>              printk("Bug\n");
> -            *(int*)0=0;
> +            BUG();
>          }
>          free_page(hdr);
>      }