From dbace38b2a1385f78cec195c1dff2a94c1d1c97f Mon Sep 17 00:00:00 2001 From: Ashish Kumar Yadav Date: Sun, 28 Mar 2021 12:46:03 +0530 Subject: [PATCH] Fixed potential buffer overflow in updatestatus --- config.def.h | 3 --- dwmblocks.c | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index 0a878c0..0eb2264 100644 --- a/config.def.h +++ b/config.def.h @@ -4,9 +4,6 @@ /* buffer size for capturing output of the programs used for updating blocks */ #define CMDOUTLENGTH 50 -/* buffer size for status text */ -#define STATUSLENGTH 256 - /* DELIMITERENDCHAR must be less than 32. * At max, DELIMITERENDCHAR - 1 number of clickable blocks are allowed. * Raw characters larger than DELIMITERENDCHAR and smaller than ' ' in ASCII diff --git a/dwmblocks.c b/dwmblocks.c index eb16f62..a38cdf6 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -13,6 +13,7 @@ #define LOCKFILE "/tmp/dwmblocks.pid" #define DELIMITERLENGTH sizeof delimiter +#define STATUSLENGTH ((sizeof blocks / sizeof blocks[0]) * (CMDOUTLENGTH + DELIMITERLENGTH)) #include "config.h" @@ -239,7 +240,7 @@ updateblock(Block *block, int sigval) void updatestatus() { - static char statustext[STATUSLENGTH + DELIMITERLENGTH]; + static char statustext[STATUSLENGTH]; char *s = statustext; Block *block;