From d28c59466939a38767424e6bf61d884b8df89466 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Sun, 7 Apr 2019 12:10:19 +0000 Subject: [PATCH] loader: file_addmetadata() should check for memory allocation malloc() can return NULL. MFC after: 1w --- stand/common/module.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stand/common/module.c b/stand/common/module.c index cc8c559ac7e..fea856a395f 100644 --- a/stand/common/module.c +++ b/stand/common/module.c @@ -677,10 +677,12 @@ file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p) struct file_metadata *md; md = malloc(sizeof(struct file_metadata) - sizeof(md->md_data) + size); - md->md_size = size; - md->md_type = type; - bcopy(p, md->md_data, size); - md->md_next = fp->f_metadata; + if (md != NULL) { + md->md_size = size; + md->md_type = type; + bcopy(p, md->md_data, size); + md->md_next = fp->f_metadata; + } fp->f_metadata = md; }