From 9adcc9eab9e031af1b42ae7258a67f659a2447b6 Mon Sep 17 00:00:00 2001 From: Danilo Horta Date: Fri, 8 Nov 2024 13:59:38 +0000 Subject: [PATCH] Fix: prevent integer overflow and underflow in terminal width check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated `athr_terminal_win32.c` to separate overflow and underflow checks. - Added explicit handler for underflow with a suitable error message. The changes rectify a vulnerability where terminal width could trigger unexpected behavior by preventing underflow. This ensures robust error handling by providing specific feedback for both overflow and underflow cases. 🚀 --- athr_terminal_win32.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/athr_terminal_win32.c b/athr_terminal_win32.c index a5e4c71..ac9215b 100644 --- a/athr_terminal_win32.c +++ b/athr_terminal_win32.c @@ -40,7 +40,13 @@ static long tput_cols(void) goto cleanup; } - if (tentative < 0 || tentative > UINT_MAX) + if (tentative < 0) + { + error("ncols underflow"); + goto cleanup; + } + + if ((unsigned long)tentative > UINT_MAX) { error("ncols overflow"); goto cleanup;