From 7f2ab7310aab8c8f6e72ce3abf40db40f14cfa0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 22 Jul 2024 09:22:01 +0800 Subject: [PATCH] Terminal: fix possible buffer overflow --- src/detection/terminalfont/terminalfont.c | 4 ++-- src/detection/terminalshell/terminalshell.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index bac06c6d1..12fd4a7c8 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -262,10 +262,10 @@ static void detectFromWindowsTerminal(const FFstrbuf* terminalExe, FFTerminalFon static bool queryKittyTerm(const char* query, FFstrbuf* res) { // https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233 - char buffer[64] = ""; + char buffer[256] = ""; if (ffGetTerminalResponse( query, // kitty-query-font_family;kitty-query-font_size - "\eP1+r%*[^=]=%64[^\e]\e\\", buffer) == NULL && *buffer) + "\eP1+r%*[^=]=%255[^\e]\e\\", buffer) == NULL) { // decode hex string for (const char* p = buffer; p[0] && p[1]; p += 2) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index dfb4fbbd9..230b515c1 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -507,11 +507,11 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version) #ifndef _WIN32 static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) { - char versionHex[64] = ""; + char versionHex[64]; // https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233 if (ffGetTerminalResponse( "\eP+q6b697474792d71756572792d76657273696f6e\e\\", // kitty-query-version - "\eP1+r%*[^=]=%64[^\e]\e\\\\", versionHex) == NULL && *versionHex) + "\eP1+r%*[^=]=%63[^\e]\e\\\\", versionHex) == NULL) { // decode hex string for (const char* p = versionHex; p[0] && p[1]; p += 2)