dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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