Blame SOURCES/0476-kern-misc-Add-STRING-type-for-internal-printf-format.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Thomas Frauendorfer | Miray Software <tf@miray.de>
80913e
Date: Mon, 15 Feb 2021 14:04:26 +0100
80913e
Subject: [PATCH] kern/misc: Add STRING type for internal printf() format
80913e
 handling
80913e
80913e
Set printf() argument type for "%s" to new type STRING. This is in
80913e
preparation for a follow up patch to compare a printf() format string
80913e
against an expected printf() format string.
80913e
80913e
For "%s" the corresponding printf() argument is dereferenced as pointer
80913e
while all other argument types are defined as integer value. However,
80913e
when validating a printf() format it is necessary to differentiate "%s"
80913e
from "%p" and other integers. So, let's do that.
80913e
80913e
Signed-off-by: Thomas Frauendorfer | Miray Software <tf@miray.de>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/kern/misc.c | 13 +++++++++++--
80913e
 1 file changed, 11 insertions(+), 2 deletions(-)
80913e
80913e
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
80913e
index ebfcc95f01d..07456faa2a7 100644
80913e
--- a/grub-core/kern/misc.c
80913e
+++ b/grub-core/kern/misc.c
80913e
@@ -37,7 +37,8 @@ union printf_arg
80913e
   enum
80913e
     {
80913e
       INT, LONG, LONGLONG,
80913e
-      UNSIGNED_INT = 3, UNSIGNED_LONG, UNSIGNED_LONGLONG
80913e
+      UNSIGNED_INT = 3, UNSIGNED_LONG, UNSIGNED_LONGLONG,
80913e
+      STRING
80913e
     } type;
80913e
   long long ll;
80913e
 };
80913e
@@ -857,12 +858,14 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args)
80913e
 	  args->ptr[curn].type = INT + longfmt;
80913e
 	  break;
80913e
 	case 'p':
80913e
-	case 's':
80913e
 	  if (sizeof (void *) == sizeof (long long))
80913e
 	    args->ptr[curn].type = UNSIGNED_LONGLONG;
80913e
 	  else
80913e
 	    args->ptr[curn].type = UNSIGNED_INT;
80913e
 	  break;
80913e
+	case 's':
80913e
+	  args->ptr[curn].type = STRING;
80913e
+	  break;
80913e
 	case 'C':
80913e
 	case 'c':
80913e
 	  args->ptr[curn].type = INT;
80913e
@@ -897,6 +900,12 @@ parse_printf_args (const char *fmt0, struct printf_args *args, va_list args_in)
80913e
       case UNSIGNED_LONGLONG:
80913e
 	args->ptr[n].ll = va_arg (args_in, long long);
80913e
 	break;
80913e
+      case STRING:
80913e
+	if (sizeof (void *) == sizeof (long long))
80913e
+	  args->ptr[n].ll = va_arg (args_in, long long);
80913e
+	else
80913e
+	  args->ptr[n].ll = va_arg (args_in, unsigned int);
80913e
+	break;
80913e
       }
80913e
 }
80913e