From: Alec Brown Date: Tue, 28 Jan 2025 05:15:50 +0000 (+0000) Subject: fs/sfs: Check if allocated memory is NULL X-Git-Tag: grub-2.14-rc1~274 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3c578a56f9294e286b6028ca7c1def997a17b15;p=thirdparty%2Fgrub.git fs/sfs: Check if allocated memory is NULL When using grub_zalloc(), if we are out of memory, this function can fail. After allocating memory, we should check if grub_zalloc() returns NULL. If so, we should handle this error. Fixes: CID 473856 Signed-off-by: Alec Brown Reviewed-by: Ross Philipson Reviewed-by: Daniel Kiper --- diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index 88705b3a2..bad4ae8d1 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -429,6 +429,9 @@ grub_sfs_mount (grub_disk_t disk) - 24 /* offsetof (struct grub_sfs_objc, objects) */ - 25); /* offsetof (struct grub_sfs_obj, filename) */ data->label = grub_zalloc (max_len + 1); + if (data->label == NULL) + goto fail; + grub_strncpy (data->label, (char *) rootobjc->objects[0].filename, max_len); grub_free (rootobjc_data);