fwupd/SOURCES/0009-trivial-Fix-a-buffer-overread-spotted-by-AddressSani.patch
2021-09-09 16:50:53 +00:00

35 lines
1019 B
Diff

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