0001-cbfstool-Make-use-of-spurious-null-termination.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From f22f408956bf02609a96b7d72fb3321da159bfc6 Mon Sep 17 00:00:00 2001
  2. From: Nico Huber <nico.huber@secunet.com>
  3. Date: Tue, 22 Jun 2021 13:49:44 +0000
  4. Subject: [PATCH 1/1] cbfstool: Make use of spurious null-termination
  5. The null-termination of `filetypes` was added after the code was
  6. written, obviously resulting in NULL dereferences. As some more
  7. code has grown around the termination, it's hard to revert the
  8. regression, so let's update the code that still used the array
  9. length.
  10. This fixes commit 7f5f9331d1 (util/cbfstool: fix buffer over-read)
  11. which actually did fix something, but only one path while it broke
  12. two others. We should be careful with fixes, they can always break
  13. something else. Especially when a dumb tool triggered the patching
  14. it seems likely that fewer people looked into related code.
  15. Change-Id: If2ece1f5ad62952ed2e57769702e318ba5468f0c
  16. Signed-off-by: Nico Huber <nico.huber@secunet.com>
  17. Reviewed-on: https://review.coreboot.org/c/coreboot/+/55763
  18. Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
  19. Reviewed-by: Julius Werner <jwerner@chromium.org>
  20. ---
  21. util/cbfstool/common.c | 8 ++++----
  22. 1 file changed, 4 insertions(+), 4 deletions(-)
  23. diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
  24. index e2ed38ffc4..539d0baccf 100644
  25. --- a/util/cbfstool/common.c
  26. +++ b/util/cbfstool/common.c
  27. @@ -168,10 +168,10 @@ void print_supported_architectures(void)
  28. void print_supported_filetypes(void)
  29. {
  30. - int i, number = ARRAY_SIZE(filetypes);
  31. + int i;
  32. - for (i=0; i<number; i++) {
  33. - printf(" %s%c", filetypes[i].name, (i==(number-1))?'\n':',');
  34. + for (i=0; filetypes[i].name; i++) {
  35. + printf(" %s%c", filetypes[i].name, filetypes[i + 1].name ? ',' : '\n');
  36. if ((i%8) == 7)
  37. printf("\n");
  38. }
  39. @@ -180,7 +180,7 @@ void print_supported_filetypes(void)
  40. uint64_t intfiletype(const char *name)
  41. {
  42. size_t i;
  43. - for (i = 0; i < (sizeof(filetypes) / sizeof(struct typedesc_t)); i++)
  44. + for (i = 0; filetypes[i].name; i++)
  45. if (strcmp(filetypes[i].name, name) == 0)
  46. return filetypes[i].type;
  47. return -1;
  48. --
  49. 2.39.2