0145-kern-misc-Add-STRING-type-for-internal-printf-format.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 1a2a5aff71e8edba436398492279de434abfe7a3 Mon Sep 17 00:00:00 2001
  2. From: Thomas Frauendorfer | Miray Software <tf@miray.de>
  3. Date: Mon, 15 Feb 2021 14:04:26 +0100
  4. Subject: [PATCH] kern/misc: Add STRING type for internal printf() format
  5. handling
  6. Set printf() argument type for "%s" to new type STRING. This is in
  7. preparation for a follow up patch to compare a printf() format string
  8. against an expected printf() format string.
  9. For "%s" the corresponding printf() argument is dereferenced as pointer
  10. while all other argument types are defined as integer value. However,
  11. when validating a printf() format it is necessary to differentiate "%s"
  12. from "%p" and other integers. So, let's do that.
  13. Signed-off-by: Thomas Frauendorfer | Miray Software <tf@miray.de>
  14. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  15. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  16. ---
  17. grub-core/kern/misc.c | 13 +++++++++++--
  18. 1 file changed, 11 insertions(+), 2 deletions(-)
  19. diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
  20. index 50bf3ee..22417f7 100644
  21. --- a/grub-core/kern/misc.c
  22. +++ b/grub-core/kern/misc.c
  23. @@ -33,7 +33,8 @@ union printf_arg
  24. enum
  25. {
  26. INT, LONG, LONGLONG,
  27. - UNSIGNED_INT = 3, UNSIGNED_LONG, UNSIGNED_LONGLONG
  28. + UNSIGNED_INT = 3, UNSIGNED_LONG, UNSIGNED_LONGLONG,
  29. + STRING
  30. } type;
  31. long long ll;
  32. };
  33. @@ -776,12 +777,14 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args)
  34. args->ptr[curn].type = INT + longfmt;
  35. break;
  36. case 'p':
  37. - case 's':
  38. if (sizeof (void *) == sizeof (long long))
  39. args->ptr[curn].type = UNSIGNED_LONGLONG;
  40. else
  41. args->ptr[curn].type = UNSIGNED_INT;
  42. break;
  43. + case 's':
  44. + args->ptr[curn].type = STRING;
  45. + break;
  46. case 'C':
  47. case 'c':
  48. args->ptr[curn].type = INT;
  49. @@ -816,6 +819,12 @@ parse_printf_args (const char *fmt0, struct printf_args *args, va_list args_in)
  50. case UNSIGNED_LONGLONG:
  51. args->ptr[n].ll = va_arg (args_in, long long);
  52. break;
  53. + case STRING:
  54. + if (sizeof (void *) == sizeof (long long))
  55. + args->ptr[n].ll = va_arg (args_in, long long);
  56. + else
  57. + args->ptr[n].ll = va_arg (args_in, unsigned int);
  58. + break;
  59. }
  60. }
  61. --
  62. 2.14.2