[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH] lib/alloc: check for missing palloc implementation



Hi Hugo,

thanks a lot for your work. This is a good finding.

On 08.01.20 11:26, Hugo Lefeuvre wrote:
Add NULL pointer check to uk_palloc in order to avoid NULL pointer
dereference when palloc is not implemented by the allocator.
---
  lib/ukalloc/include/uk/alloc.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ukalloc/include/uk/alloc.h b/lib/ukalloc/include/uk/alloc.h
index 634bb3f..2e73ab6 100644
--- a/lib/ukalloc/include/uk/alloc.h
+++ b/lib/ukalloc/include/uk/alloc.h
@@ -201,7 +201,7 @@ static inline void *uk_do_palloc(struct uk_alloc *a, size_t 
order)
  }
  static inline void *uk_palloc(struct uk_alloc *a, size_t order)
  {
-       if (unlikely(!a))
+       if (unlikely(!a) || unlikely(!a->palloc))

Interesting... I am actually curious what the compiler does with your condition. I would have written it with just one encapsulating `unlikely` hint:

if (unlikely(!a || !a->palloc))

Maybe there is no difference and it turns out to be different coding style. In general, having just one encapsulating hint maybe easier to read.

What do you think?

Thanks,

Simon

                return NULL;
        return a->palloc(a, order);
  }


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.