Make safe filling the who buffer
parent
a26a6fee8d
commit
f1b1ffe79f
18
handle.c
18
handle.c
|
@ -152,8 +152,10 @@ static void handle366(char *prefix, char *params) {
|
|||
ircFmt("WHO %s\r\n", chan);
|
||||
}
|
||||
|
||||
static char whoBuf[4096];
|
||||
static size_t whoLen;
|
||||
static struct {
|
||||
char buf[4096];
|
||||
size_t len;
|
||||
} who;
|
||||
|
||||
static void handle352(char *prefix, char *params) {
|
||||
(void)prefix;
|
||||
|
@ -163,21 +165,23 @@ static void handle352(char *prefix, char *params) {
|
|||
shift(¶ms);
|
||||
shift(¶ms);
|
||||
char *nick = shift(¶ms);
|
||||
whoLen += snprintf(
|
||||
&whoBuf[whoLen], sizeof(whoBuf) - whoLen,
|
||||
size_t cap = sizeof(who.buf) - who.len;
|
||||
int len = snprintf(
|
||||
&who.buf[who.len], cap,
|
||||
"%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) {
|
||||
(void)prefix;
|
||||
shift(¶ms);
|
||||
char *chan = shift(¶ms);
|
||||
whoLen = 0;
|
||||
who.len = 0;
|
||||
uiFmt(
|
||||
L"In \3%d%s\3 are %s",
|
||||
color(chan), chan, whoBuf
|
||||
color(chan), chan, who.buf
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue