File shim-alloc-one-more-byte-for-sprintf.patch of Package shim

From 21276134c24bf5e2a4728a14b920b6c23942d83c Mon Sep 17 00:00:00 2001
From: Dennis Tseng <dennis.tseng@suse.com>
Date: Tue, 15 Apr 2025 17:35:21 +0800
Subject: [PATCH] Realloc() needs one more byte for sprintf()

In generate_sbat_var_defs.c, realloc() should allocate one more byte for
the end of string '\0' when running sprintf() later.

Suppose we use fgets() to get line="abc\n", so strlen(line)=4 bytes.
realloc(...,strlen(line),1) will allocate 5 bytes which is not capable to
save line(3 bytes),'\' and 'n'(2 bytes) pluses extra '\0' byte totally 6 bytes
when running sprintf(.....,"%s\\n", line) later on.
where '\n' of line has been removed in line[strlen(line) - 1] = 0;

Signed-off-by: Dennis Tseng <dennis.tseng@suse.com>
---
 generate_sbat_var_defs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: shim-16.0/generate_sbat_var_defs.c
===================================================================
--- shim-16.0.orig/generate_sbat_var_defs.c
+++ shim-16.0/generate_sbat_var_defs.c
@@ -57,7 +57,7 @@ readfile(char *SbatLevel_Variable)
 			       fgets(line, sizeof(line), varfilep) != NULL) {
 				char *new = NULL;
 				new = realloc(revlistentry->revocations,
-				              revocationsp + strlen(line) + 1);
+				              revocationsp + strlen(line) + 2);
 				if (new == NULL) {
 					ret = -1;
 					goto err;
openSUSE Build Service is sponsored by