0059-fs-sfs-Check-if-allocated-memory-is-NULL.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. From afacc73c48934b66e18d9d12fef2ae6b44f105ea Mon Sep 17 00:00:00 2001
  2. From: Alec Brown <alec.r.brown@oracle.com>
  3. Date: Tue, 28 Jan 2025 05:15:50 +0000
  4. Subject: [PATCH] fs/sfs: Check if allocated memory is NULL
  5. When using grub_zalloc(), if we are out of memory, this function can fail.
  6. After allocating memory, we should check if grub_zalloc() returns NULL.
  7. If so, we should handle this error.
  8. Fixes: CID 473856
  9. Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
  10. Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
  11. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  12. Upstream: e3c578a56f9294e286b6028ca7c1def997a17b15
  13. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  14. ---
  15. grub-core/fs/sfs.c | 3 +++
  16. 1 file changed, 3 insertions(+)
  17. diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c
  18. index 88705b3a2..bad4ae8d1 100644
  19. --- a/grub-core/fs/sfs.c
  20. +++ b/grub-core/fs/sfs.c
  21. @@ -429,6 +429,9 @@ grub_sfs_mount (grub_disk_t disk)
  22. - 24 /* offsetof (struct grub_sfs_objc, objects) */
  23. - 25); /* offsetof (struct grub_sfs_obj, filename) */
  24. data->label = grub_zalloc (max_len + 1);
  25. + if (data->label == NULL)
  26. + goto fail;
  27. +
  28. grub_strncpy (data->label, (char *) rootobjc->objects[0].filename, max_len);
  29. grub_free (rootobjc_data);
  30. --
  31. 2.50.1