Blame SOURCES/0006-thin_metadata_size-Fix-potential-string-overflow.patch

5a5b1b
From 35e96e07c956a501cb8a12f5b873db173bb09179 Mon Sep 17 00:00:00 2001
5a5b1b
From: Ming-Hung Tsai <mtsai@redhat.com>
5a5b1b
Date: Wed, 2 Jun 2021 11:39:01 +0800
5a5b1b
Subject: [PATCH 06/10] [thin_metadata_size] Fix potential string overflow
5a5b1b
5a5b1b
---
5a5b1b
 thin-provisioning/thin_metadata_size.cc | 10 +++++++---
5a5b1b
 1 file changed, 7 insertions(+), 3 deletions(-)
5a5b1b
5a5b1b
diff --git a/thin-provisioning/thin_metadata_size.cc b/thin-provisioning/thin_metadata_size.cc
5a5b1b
index b6a5718..f14696c 100644
5a5b1b
--- a/thin-provisioning/thin_metadata_size.cc
5a5b1b
+++ b/thin-provisioning/thin_metadata_size.cc
5a5b1b
@@ -192,9 +192,13 @@ static void printf_aligned(struct global *g, char const *a, char const *b, char
5a5b1b
 {
5a5b1b
 	char buf[80];
5a5b1b
 
5a5b1b
-	strcpy(buf, b);
5a5b1b
-	if (units)
5a5b1b
-		strcat(buf, mandatory ? "{" :"["), strcat(buf, g->unit.chars), strcat(buf, mandatory ? "}" : "]");
5a5b1b
+	if (units) {
5a5b1b
+		char left_bracket = mandatory ? '{' : '[';
5a5b1b
+		char right_bracket = mandatory ? '}' : ']';
5a5b1b
+		snprintf(buf, 80, "%s%c%s%c", b, left_bracket, g->unit.chars, right_bracket);
5a5b1b
+	} else {
5a5b1b
+		snprintf(buf, 80, "%s", b);
5a5b1b
+	}
5a5b1b
 
5a5b1b
 	printf("\t%-4s%-44s%s\n", a, buf, c);
5a5b1b
 }
5a5b1b
-- 
5a5b1b
1.8.3.1
5a5b1b