status

statusbar program for dwm
git clone anongit@rnpnr.xyz:status.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 6f0913822ab45ff7f8ee3d8d0d462a57cf2416fa
Parent: eb159931ddb30aa72871470b74ddeb4c0b6c4e3c
Author: Randy Palamar
Date:   Sat, 27 Mar 2021 21:05:24 -0600

fix potential statusbar buffer overflow

this would never occur by default. using the default bar length and
block length you would need to configure 32 separate blocks to hit
this. nevertheless it was fixed.

Diffstat:
Mstatus.c | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/status.c b/status.c @@ -40,14 +40,25 @@ updatestatus(void) static char status[STATUSLEN]; struct Block *b; char *s = status; + ssize_t rem; for (b = blks; b < dirty; b++) s += b->len; - for (; b->fn; b++) { - memcpy(s, b->curstr, b->len); - s += b->len; + rem = sizeof(status) - (s - status); + + for (; rem > 0 && b->fn; b++) { + if (b->len < (size_t)rem) { + memcpy(s, b->curstr, b->len); + s += b->len; + } else { + memcpy(s, b->curstr, rem); + s += rem; + } + rem = sizeof(status) - (s - status); } + if (rem < 0) + s += rem; s[0] = '\0'; dirty = NULL;