[PATCH] xen: Handle malloc failure in errmsg function
Francois Berder
fberder at outlook.fr
Mon Apr 20 21:15:24 CEST 2026
Signed-off-by: Francois Berder <fberder at outlook.fr>
---
drivers/xen/xenbus.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/xen/xenbus.c b/drivers/xen/xenbus.c
index 36de5255099..92991e2b8f3 100644
--- a/drivers/xen/xenbus.c
+++ b/drivers/xen/xenbus.c
@@ -280,12 +280,18 @@ static char *errmsg(struct xsd_sockmsg *rep)
if (!rep) {
char msg[] = "No reply";
size_t len = strlen(msg) + 1;
-
- return memcpy(malloc(len), msg, len);
+ res = malloc(len);
+ if (!res)
+ return NULL;
+ return memcpy(res, msg, len);
}
if (rep->type != XS_ERROR)
return NULL;
res = malloc(rep->len + 1);
+ if (!res) {
+ free(rep);
+ return NULL;
+ }
memcpy(res, rep + 1, rep->len);
res[rep->len] = 0;
free(rep);
--
2.43.0
More information about the U-Boot
mailing list