0062-kern-partition-Check-for-NULL-before-dereferencing-i.patch 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From bc9c468a2ce84bc767234eec888b71f1bc744fff Mon Sep 17 00:00:00 2001
  2. From: Darren Kenny <darren.kenny@oracle.com>
  3. Date: Fri, 23 Oct 2020 09:49:59 +0000
  4. Subject: [PATCH] kern/partition: Check for NULL before dereferencing input
  5. string
  6. There is the possibility that the value of str comes from an external
  7. source and continuing to use it before ever checking its validity is
  8. wrong. So, needs fixing.
  9. Additionally, drop unneeded part initialization.
  10. Fixes: CID 292444
  11. Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
  12. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  13. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  14. ---
  15. grub-core/kern/partition.c | 5 ++++-
  16. 1 file changed, 4 insertions(+), 1 deletion(-)
  17. diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c
  18. index e499147..b10a184 100644
  19. --- a/grub-core/kern/partition.c
  20. +++ b/grub-core/kern/partition.c
  21. @@ -109,11 +109,14 @@ grub_partition_map_probe (const grub_partition_map_t partmap,
  22. grub_partition_t
  23. grub_partition_probe (struct grub_disk *disk, const char *str)
  24. {
  25. - grub_partition_t part = 0;
  26. + grub_partition_t part;
  27. grub_partition_t curpart = 0;
  28. grub_partition_t tail;
  29. const char *ptr;
  30. + if (str == NULL)
  31. + return 0;
  32. +
  33. part = tail = disk->partition;
  34. for (ptr = str; *ptr;)
  35. --
  36. 2.14.2