From 384b9691f690e5e00398f9626c44532df5f269d2 Mon Sep 17 00:00:00 2001 From: Unsung Lee Date: Fri, 22 Nov 2024 14:57:18 +0900 Subject: [PATCH] kernel: Increase +1 size of destination buffer to avoid overflow Increase the size of the destination buffer to one more than the data to be copied through sscanf. For example, if we want to copy BUFF_MAX size from source buffer then destination buffer size should be larger than BUFF_MAX (e.g., BUFF_MAX + 1) to avoid buffer overflow. By doing so, regardless of the size of the source buffer, only up to BUFF_MAX size is copied to the destination buffer. Change-Id: I63cefd0f325d89fa41b6fe4241f871191c0884fa Signed-off-by: Unsung Lee --- src/util/kernel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/kernel.c b/src/util/kernel.c index e3dedda..c6dd3f8 100644 --- a/src/util/kernel.c +++ b/src/util/kernel.c @@ -452,7 +452,7 @@ static inline bool is_new_entry(const char *str) static unsigned long get_gpu_mem_size(FILE *smaps_fd, char *buffer) { unsigned long mem_size = 0; - char name[BUFF_MAX]; + char name[BUFF_MAX + 1]; if (!gpu_mem_node) return 0; -- 2.34.1