Skip to content

Commit 322bddb

Browse files
Fix maskname() buffer size
Found by: jack3 Patch by: michaelortmann Fixes: eggheads#1434
1 parent 26a8bc9 commit 322bddb

File tree

3 files changed

+70
-133
lines changed

3 files changed

+70
-133
lines changed

src/cmds.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,30 +2605,21 @@ char *stripmasktype(int x)
26052605

26062606
static char *stripmaskname(int x)
26072607
{
2608-
static char s[161];
2609-
int i = 0;
2608+
static char s[128];
2609+
int i;
26102610

2611-
s[i] = 0;
2612-
if (x & STRIP_COLOR)
2613-
i += my_strcpy(s + i, "color, ");
2614-
if (x & STRIP_BOLD)
2615-
i += my_strcpy(s + i, "bold, ");
2616-
if (x & STRIP_REVERSE)
2617-
i += my_strcpy(s + i, "reverse, ");
2618-
if (x & STRIP_UNDERLINE)
2619-
i += my_strcpy(s + i, "underline, ");
2620-
if (x & STRIP_ANSI)
2621-
i += my_strcpy(s + i, "ansi, ");
2622-
if (x & STRIP_BELLS)
2623-
i += my_strcpy(s + i, "bells, ");
2624-
if (x & STRIP_ORDINARY)
2625-
i += my_strcpy(s + i, "ordinary, ");
2626-
if (x & STRIP_ITALICS)
2627-
i += my_strcpy(s + i, "italics, ");
2628-
if (!i)
2629-
strcpy(s, "none");
2630-
else
2611+
if ((i = snprintf(s, sizeof s, "%s%s%s%s%s%s%s%s",
2612+
(x & STRIP_COLOR) ? "color, " : "",
2613+
(x & STRIP_BOLD) ? "bold, " : "",
2614+
(x & STRIP_REVERSE) ? "reverse, " : "",
2615+
(x & STRIP_UNDERLINE) ? "underline, " : "",
2616+
(x & STRIP_ANSI) ? "ansi, " : "",
2617+
(x & STRIP_BELLS) ? "bells, " : "",
2618+
(x & STRIP_ORDINARY) ? "ordinary, " : "",
2619+
(x & STRIP_ITALICS) ? "italics, " : "")))
26312620
s[i - 2] = 0;
2621+
else
2622+
strcpy(s, "none");
26322623
return s;
26332624
}
26342625

src/flags.c

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -203,63 +203,36 @@ char *masktype(int x)
203203

204204
char *maskname(int x)
205205
{
206-
static char s[275]; /* Change this if you change the levels */
207-
int i = 0; /* 6+8+7+13+6+6+6+17+5+7+8+7+9+15+17+17+24+24+(8*9)+1 */
206+
static char s[512];
207+
int i;
208208

209-
s[0] = 0;
210-
if (x & LOG_MSGS)
211-
i += my_strcpy(s, "msgs, "); /* 6 */
212-
if (x & LOG_PUBLIC)
213-
i += my_strcpy(s + i, "public, "); /* 8 */
214-
if (x & LOG_JOIN)
215-
i += my_strcpy(s + i, "joins, "); /* 7 */
216-
if (x & LOG_MODES)
217-
i += my_strcpy(s + i, "kicks/modes, "); /* 13 */
218-
if (x & LOG_CMDS)
219-
i += my_strcpy(s + i, "cmds, "); /* 6 */
220-
if (x & LOG_MISC)
221-
i += my_strcpy(s + i, "misc, "); /* 6 */
222-
if (x & LOG_BOTS)
223-
i += my_strcpy(s + i, "bots, "); /* 6 */
224-
if (x & LOG_BOTMSG)
225-
i += my_strcpy(s + i, "linked bot msgs, "); /* 17 */
226-
if ((x & LOG_RAW) && raw_log)
227-
i += my_strcpy(s + i, "raw, "); /* 5 */
228-
if (x & LOG_FILES)
229-
i += my_strcpy(s + i, "files, "); /* 7 */
230-
if (x & LOG_SERV)
231-
i += my_strcpy(s + i, "server input, "); /* 8 */
232-
if (x & LOG_DEBUG)
233-
i += my_strcpy(s + i, "debug, "); /* 7 */
234-
if (x & LOG_WALL)
235-
i += my_strcpy(s + i, "wallops, "); /* 9 */
236-
if ((x & LOG_SRVOUT) && raw_log)
237-
i += my_strcpy(s + i, "server output, "); /* 15 */
238-
if ((x & LOG_BOTNETIN) && raw_log)
239-
i += my_strcpy(s + i, "botnet incoming, "); /* 17 */
240-
if ((x & LOG_BOTNETOUT) && raw_log)
241-
i += my_strcpy(s + i, "botnet outgoing, "); /* 17 */
242-
if ((x & LOG_BOTSHRIN) && raw_log)
243-
i += my_strcpy(s + i, "incoming share traffic, "); /* 24 */
244-
if ((x & LOG_BOTSHROUT) && raw_log)
245-
i += my_strcpy(s + i, "outgoing share traffic, "); /* 24 */
246-
if (x & LOG_LEV1)
247-
i += my_strcpy(s + i, "level 1, "); /* 9 */
248-
if (x & LOG_LEV2)
249-
i += my_strcpy(s + i, "level 2, "); /* 9 */
250-
if (x & LOG_LEV3)
251-
i += my_strcpy(s + i, "level 3, "); /* 9 */
252-
if (x & LOG_LEV4)
253-
i += my_strcpy(s + i, "level 4, "); /* 9 */
254-
if (x & LOG_LEV5)
255-
i += my_strcpy(s + i, "level 5, "); /* 9 */
256-
if (x & LOG_LEV6)
257-
i += my_strcpy(s + i, "level 6, "); /* 9 */
258-
if (x & LOG_LEV7)
259-
i += my_strcpy(s + i, "level 7, "); /* 9 */
260-
if (x & LOG_LEV8)
261-
i += my_strcpy(s + i, "level 8, "); /* 9 */
262-
if (i)
209+
if ((i = snprintf(s, sizeof s, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
210+
(x & LOG_MSGS) ? "msgs, " : "",
211+
(x & LOG_PUBLIC) ? "public, " : "",
212+
(x & LOG_JOIN) ? "joins, " : "",
213+
(x & LOG_MODES) ? "kicks/modes, " : "",
214+
(x & LOG_CMDS) ? "cmds, " : "",
215+
(x & LOG_MISC) ? "misc, " : "",
216+
(x & LOG_BOTS) ? "bots, " : "",
217+
(x & LOG_BOTMSG) ? "linked bot msgs, " : "",
218+
((x & LOG_RAW) && raw_log) ? "raw, " : "",
219+
(x & LOG_FILES) ? "files, " : "",
220+
(x & LOG_SERV) ? "server input, " : "",
221+
(x & LOG_DEBUG) ? "debug, " : "",
222+
(x & LOG_WALL) ? "wallops, " : "",
223+
((x & LOG_SRVOUT) && raw_log) ? "server output, " : "",
224+
((x & LOG_BOTNETIN) && raw_log) ? "botnet incoming, " : "",
225+
((x & LOG_BOTNETOUT) && raw_log) ? "botnet outgoing, " : "",
226+
((x & LOG_BOTSHRIN) && raw_log) ? "incoming share traffic, " : "",
227+
((x & LOG_BOTSHROUT) && raw_log) ? "outgoing share traffic, " : "",
228+
(x & LOG_LEV1) ? "level 1, " : "",
229+
(x & LOG_LEV2) ? "level 2, " : "",
230+
(x & LOG_LEV3) ? "level 3, " : "",
231+
(x & LOG_LEV4) ? "level 4, " : "",
232+
(x & LOG_LEV5) ? "level 5, " : "",
233+
(x & LOG_LEV6) ? "level 6, " : "",
234+
(x & LOG_LEV7) ? "level 7, " : "",
235+
(x & LOG_LEV8) ? "level 8, " : "")))
263236
s[i - 2] = 0;
264237
else
265238
strcpy(s, "none");

src/mod/channels.mod/channels.c

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -620,61 +620,34 @@ static void channels_report(int idx, int details)
620620
dprintf(idx, "%s\n", s);
621621

622622
if (details) {
623-
s[0] = 0;
624-
i = 0;
625-
626-
if (channel_enforcebans(chan))
627-
i += my_strcpy(s + i, "enforcebans ");
628-
if (channel_dynamicbans(chan))
629-
i += my_strcpy(s + i, "dynamicbans ");
630-
if (!channel_nouserbans(chan))
631-
i += my_strcpy(s + i, "userbans ");
632-
if (channel_autoop(chan))
633-
i += my_strcpy(s + i, "autoop ");
634-
if (channel_bitch(chan))
635-
i += my_strcpy(s + i, "bitch ");
636-
if (channel_greet(chan))
637-
i += my_strcpy(s + i, "greet ");
638-
if (channel_protectops(chan))
639-
i += my_strcpy(s + i, "protectops ");
640-
if (channel_protecthalfops(chan))
641-
i += my_strcpy(s + i, "protecthalfops ");
642-
if (channel_protectfriends(chan))
643-
i += my_strcpy(s + i, "protectfriends ");
644-
if (channel_dontkickops(chan))
645-
i += my_strcpy(s + i, "dontkickops ");
646-
if (channel_logstatus(chan))
647-
i += my_strcpy(s + i, "statuslog ");
648-
if (channel_revenge(chan))
649-
i += my_strcpy(s + i, "revenge ");
650-
if (channel_revenge(chan))
651-
i += my_strcpy(s + i, "revengebot ");
652-
if (channel_secret(chan))
653-
i += my_strcpy(s + i, "secret ");
654-
if (channel_shared(chan))
655-
i += my_strcpy(s + i, "shared ");
656-
if (!channel_static(chan))
657-
i += my_strcpy(s + i, "dynamic ");
658-
if (channel_autovoice(chan))
659-
i += my_strcpy(s + i, "autovoice ");
660-
if (channel_autohalfop(chan))
661-
i += my_strcpy(s + i, "autohalfop ");
662-
if (channel_cycle(chan))
663-
i += my_strcpy(s + i, "cycle ");
664-
if (channel_seen(chan))
665-
i += my_strcpy(s + i, "seen ");
666-
if (channel_dynamicexempts(chan))
667-
i += my_strcpy(s + i, "dynamicexempts ");
668-
if (!channel_nouserexempts(chan))
669-
i += my_strcpy(s + i, "userexempts ");
670-
if (channel_dynamicinvites(chan))
671-
i += my_strcpy(s + i, "dynamicinvites ");
672-
if (!channel_nouserinvites(chan))
673-
i += my_strcpy(s + i, "userinvites ");
674-
if (channel_inactive(chan))
675-
i += my_strcpy(s + i, "inactive ");
676-
if (channel_nodesynch(chan))
677-
my_strcpy(s + i, "nodesynch ");
623+
if ((i = snprintf(s, sizeof s, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
624+
channel_enforcebans(chan) ? "enforcebans " : "",
625+
channel_dynamicbans(chan) ? "dynamicbans " : "",
626+
!channel_nouserbans(chan) ? "userbans " : "",
627+
channel_autoop(chan) ? "autoop " : "",
628+
channel_bitch(chan) ? "bitch " : "",
629+
channel_greet(chan) ? "greet " : "",
630+
channel_protectops(chan) ? "protectops " : "",
631+
channel_protecthalfops(chan) ? "protecthalfops " : "",
632+
channel_protectfriends(chan) ? "protectfriends " : "",
633+
channel_dontkickops(chan) ? "dontkickops " : "",
634+
channel_logstatus(chan) ? "statuslog " : "",
635+
channel_revenge(chan) ? "revenge " : "",
636+
channel_revengebot(chan) ? "revengebot " : "",
637+
channel_secret(chan) ? "secret " : "",
638+
channel_shared(chan) ? "shared " : "",
639+
!channel_static(chan) ? "dynamic " : "",
640+
channel_autovoice(chan) ? "autovoice " : "",
641+
channel_autohalfop(chan) ? "autohalfop " : "",
642+
channel_cycle(chan) ? "cycle " : "",
643+
channel_seen(chan) ? "seen " : "",
644+
channel_dynamicexempts(chan) ? "dynamicexempts " : "",
645+
!channel_nouserexempts(chan) ? "userexempts " : "",
646+
channel_dynamicinvites(chan) ? "dynamicinvites " : "",
647+
!channel_nouserinvites(chan) ? "userinvites " : "",
648+
channel_inactive(chan) ? "inactive " : "",
649+
channel_nodesynch(chan) ? "nodesynch " : "")))
650+
s[i - 2] = 0;
678651

679652
dprintf(idx, " Options: %s\n", s);
680653

0 commit comments

Comments
 (0)