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

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