Blame SOURCES/0011-Fix-potential-buffer-overrun-in-snprintf-calls.patch

d202f6
From a26eb6eba3f318271d3fbd52152ad43acfc15393 Mon Sep 17 00:00:00 2001
d202f6
From: Phil Sutter <phil@nwl.cc>
d202f6
Date: Thu, 24 Mar 2022 18:14:50 +0100
d202f6
Subject: [PATCH] Fix potential buffer overrun in snprintf() calls
d202f6
d202f6
When consecutively printing into the same buffer at increasing offset,
d202f6
reduce buffer size passed to snprintf() to not defeat its size checking.
d202f6
d202f6
Signed-off-by: Phil Sutter <phil@nwl.cc>
d202f6
(cherry picked from commit 0e05989f3247e9aef0d96aafc144b2d853732891)
d202f6
---
d202f6
 src/process.c | 2 +-
d202f6
 src/queue.c   | 4 ++--
d202f6
 2 files changed, 3 insertions(+), 3 deletions(-)
d202f6
d202f6
diff --git a/src/process.c b/src/process.c
d202f6
index 3ddad5ffa7959..08598eeae84de 100644
d202f6
--- a/src/process.c
d202f6
+++ b/src/process.c
d202f6
@@ -84,7 +84,7 @@ void fork_process_dump(int fd)
d202f6
 	int size = 0;
d202f6
 
d202f6
 	list_for_each_entry(this, &process_list, head) {
d202f6
-		size += snprintf(buf+size, sizeof(buf),
d202f6
+		size += snprintf(buf + size, sizeof(buf) - size,
d202f6
 				 "PID=%u type=%s\n",
d202f6
 				 this->pid,
d202f6
 				 this->type < CTD_PROC_MAX ?
d202f6
diff --git a/src/queue.c b/src/queue.c
d202f6
index 76425b18495b5..e94dc7c45d1fd 100644
d202f6
--- a/src/queue.c
d202f6
+++ b/src/queue.c
d202f6
@@ -69,12 +69,12 @@ void queue_stats_show(int fd)
d202f6
 	int size = 0;
d202f6
 	char buf[512];
d202f6
 
d202f6
-	size += snprintf(buf+size, sizeof(buf),
d202f6
+	size += snprintf(buf + size, sizeof(buf) - size,
d202f6
 			 "allocated queue nodes:\t\t%12u\n\n",
d202f6
 			 qobjects_num);
d202f6
 
d202f6
 	list_for_each_entry(this, &queue_list, list) {
d202f6
-		size += snprintf(buf+size, sizeof(buf),
d202f6
+		size += snprintf(buf + size, sizeof(buf) - size,
d202f6
 				 "queue %s:\n"
d202f6
 				 "current elements:\t\t%12u\n"
d202f6
 				 "maximum elements:\t\t%12u\n"
d202f6
-- 
d202f6
2.34.1
d202f6