Make safe filling the who buffer

master
Curtis McEnroe 2018-08-07 00:12:08 -04:00
parent a26a6fee8d
commit f1b1ffe79f
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 11 additions and 7 deletions

View File

@ -152,8 +152,10 @@ static void handle366(char *prefix, char *params) {
ircFmt("WHO %s\r\n", chan); ircFmt("WHO %s\r\n", chan);
} }
static char whoBuf[4096]; static struct {
static size_t whoLen; char buf[4096];
size_t len;
} who;
static void handle352(char *prefix, char *params) { static void handle352(char *prefix, char *params) {
(void)prefix; (void)prefix;
@ -163,21 +165,23 @@ static void handle352(char *prefix, char *params) {
shift(&params); shift(&params);
shift(&params); shift(&params);
char *nick = shift(&params); char *nick = shift(&params);
whoLen += snprintf( size_t cap = sizeof(who.buf) - who.len;
&whoBuf[whoLen], sizeof(whoBuf) - whoLen, int len = snprintf(
&who.buf[who.len], cap,
"%s\3%d%s\3", "%s\3%d%s\3",
(whoLen ? ", " : ""), color(user), nick (who.len ? ", " : ""), color(user), nick
); );
if ((size_t)len < cap) who.len += len;
} }
static void handle315(char *prefix, char *params) { static void handle315(char *prefix, char *params) {
(void)prefix; (void)prefix;
shift(&params); shift(&params);
char *chan = shift(&params); char *chan = shift(&params);
whoLen = 0; who.len = 0;
uiFmt( uiFmt(
L"In \3%d%s\3 are %s", L"In \3%d%s\3 are %s",
color(chan), chan, whoBuf color(chan), chan, who.buf
); );
} }