Re: [PATCH] unicode: mkutf8data: Add malloc return value detection

From: Matthew Wilcox
Date: Fri Oct 14 2022 - 09:03:41 EST


On Fri, Oct 14, 2022 at 03:57:10PM +0800, Li zeming wrote:
> Add the check and judgment statement of malloc return value.

Why? Just to shut up some static checker?

> +++ b/fs/unicode/mkutf8data.c
> @@ -495,6 +495,9 @@ static struct node *alloc_node(struct node *parent)
> int bitnum;
>
> node = malloc(sizeof(*node));
> + if (unlikely(!node))
> + return NULL;
> +

Right, so now alloc_node() can return NULL when it couldn't before.
Look at the callers ...

while (keybits) {
if (!*cursor)
*cursor = alloc_node(node);
node = *cursor;
if (node->nextbyte)
key++;

They're unprepared for alloc_node() to return NULL, so all you've done
is move the crash.