ivi-shell: replace MEM_ALLOC() with mostly xcalloc()
Drop the even more home-grown alloc wrapper and use the xalloc.h wrappers directly. xcalloc() is added and used, because calloc() will detect integer overflows in the size multiplication, while doing a simple multiplication in the caller is subject to overflows which may result in allocating not what was expected, subjecting to out-of-bounds access. All MEM_ALLOC() calls that had a meaningful multiplication in them were converted to xcalloc(), the rest to xzalloc(). Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
@@ -57,6 +57,7 @@ fail_on_null(void *p, size_t size, char *file, int32_t line)
|
||||
|
||||
#define xmalloc(s) (fail_on_null(malloc(s), (s), __FILE__, __LINE__))
|
||||
#define xzalloc(s) (fail_on_null(zalloc(s), (s), __FILE__, __LINE__))
|
||||
#define xcalloc(n, s) (fail_on_null(calloc(n, s), (n) * (s), __FILE__, __LINE__))
|
||||
#define xstrdup(s) (fail_on_null(strdup(s), 0, __FILE__, __LINE__))
|
||||
#define xrealloc(p, s) (fail_on_null(realloc(p, s), (s), __FILE__, __LINE__))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user