Blame SOURCES/0009-trivial-Fix-a-buffer-overread-spotted-by-AddressSani.patch

9874f4
From b743836b16c64e2d726f85113cd4ab6f18ed4df0 Mon Sep 17 00:00:00 2001
9874f4
From: Richard Hughes <richard@hughsie.com>
9874f4
Date: Mon, 8 Feb 2021 16:47:05 +0000
9874f4
Subject: [PATCH 09/11] trivial: Fix a buffer-overread spotted by
9874f4
 AddressSanitizer
9874f4
9874f4
---
9874f4
 libfwupdplugin/fu-common.c | 6 ++----
9874f4
 1 file changed, 2 insertions(+), 4 deletions(-)
9874f4
9874f4
diff --git libfwupdplugin/fu-common.c libfwupdplugin/fu-common.c
9874f4
index d4dd4aef..094f2d23 100644
9874f4
--- libfwupdplugin/fu-common.c
9874f4
+++ libfwupdplugin/fu-common.c
9874f4
@@ -1856,14 +1856,12 @@ fu_common_strsafe (const gchar *str, gsize maxsz)
9874f4
 	gboolean valid = FALSE;
9874f4
 	g_autoptr(GString) tmp = NULL;
9874f4
 
9874f4
-	g_return_val_if_fail (maxsz > 0, NULL);
9874f4
-
9874f4
 	/* sanity check */
9874f4
-	if (str == NULL)
9874f4
+	if (str == NULL || maxsz == 0)
9874f4
 		return NULL;
9874f4
 
9874f4
 	/* replace non-printable chars with '.' */
9874f4
-	tmp = g_string_sized_new (strlen (str));
9874f4
+	tmp = g_string_sized_new (maxsz);
9874f4
 	for (gsize i = 0; str[i] != '\0' && i < maxsz; i++) {
9874f4
 		if (!g_ascii_isprint (str[i])) {
9874f4
 			g_string_append_c (tmp, '.');
9874f4
-- 
9874f4
2.29.2
9874f4