diff --git a/src/chan.h b/src/chan.h index be0668dde..77475ab9b 100644 --- a/src/chan.h +++ b/src/chan.h @@ -154,9 +154,9 @@ struct chan_t { struct chanset_t { struct chanset_t *next; struct chan_t channel; - char dname[81]; /* display name (!eggdev) - THIS IS ALWAYS SET*/ - char name[81]; /* actual name (!ABCDEeggdev) - THIS IS SET WHEN THE BOT - * ACTUALLY JOINS THE CHANNEL */ + char dname[CHANNELLEN + 1]; /* display name (!foo) - THIS IS ALWAYS SET */ + char name[CHANNELLEN + 1]; /* actual name (!BARfoo) - THIS IS SET WHEN THE BOT + * ACTUALLY JOINS THE CHANNEL */ char need_op[121]; char need_key[121]; char need_limit[121]; diff --git a/src/eggdrop.h b/src/eggdrop.h index 03b83baa3..a0b0a52dd 100644 --- a/src/eggdrop.h +++ b/src/eggdrop.h @@ -47,8 +47,9 @@ * You should leave this at 32 characters and modify nick-len in the * configuration file instead. */ -#define HANDLEN 32 /* valid values 9->NICKMAX */ -#define NICKMAX 32 /* valid values HANDLEN->32 */ +#define CHANNELLEN 80 /* FIXME see issue #3 and issue #38 and rfc1459 <= 200 */ +#define HANDLEN 32 /* valid values 9->NICKMAX */ +#define NICKMAX 32 /* valid values HANDLEN->32 */ /* Handy string lengths */ @@ -409,17 +410,17 @@ struct dcc_t { }; struct chat_info { - char *away; /* non-NULL if user is away */ - int msgs_per_sec; /* used to stop flooding */ - int con_flags; /* with console: what to show */ - int strip_flags; /* what codes to strip (b,r,u,c,a,g,*) */ - char con_chan[81]; /* with console: what channel to view */ - int channel; /* 0=party line, -1=off */ - struct msgq *buffer; /* a buffer of outgoing lines - * (for .page cmd) */ - int max_line; /* maximum lines at once */ - int line_count; /* number of lines sent since last page */ - int current_lines; /* number of lines total stored */ + char *away; /* non-NULL if user is away */ + int msgs_per_sec; /* used to stop flooding */ + int con_flags; /* with console: what to show */ + int strip_flags; /* what codes to strip (b,r,u,c,a,g,*) */ + char con_chan[CHANNELLEN + 1]; /* with console: what channel to view */ + int channel; /* 0=party line, -1=off */ + struct msgq *buffer; /* a buffer of outgoing lines + * (for .page cmd) */ + int max_line; /* maximum lines at once */ + int line_count; /* number of lines sent since last page */ + int current_lines; /* number of lines total stored */ char *su_nick; }; diff --git a/src/mod/channels.mod/cmdschan.c b/src/mod/channels.mod/cmdschan.c index a84352aa8..a263f4681 100644 --- a/src/mod/channels.mod/cmdschan.c +++ b/src/mod/channels.mod/cmdschan.c @@ -935,7 +935,7 @@ static void cmd_stick_yn(int idx, char *par, int yn) { int i = 0, j; struct chanset_t *chan, *achan; - char *stick_type, s[UHOSTLEN], chname[81]; + char *stick_type, s[UHOSTLEN], chname[CHANNELLEN + 1]; module_entry *me; stick_type = newsplit(&par); diff --git a/src/mod/channels.mod/tclchan.c b/src/mod/channels.mod/tclchan.c index 62fa8a8b9..1991b2b72 100644 --- a/src/mod/channels.mod/tclchan.c +++ b/src/mod/channels.mod/tclchan.c @@ -2100,8 +2100,7 @@ static int tcl_channel_add(Tcl_Interp *irp, char *newname, char *options) * any code later on. chan->name gets updated with the channel name as * the server knows it, when we join the channel. */ - strncpy(chan->dname, newname, 81); - chan->dname[80] = 0; + strlcpy(chan->dname, newname, sizeof chan->dname); /* Initialize chan->channel info */ init_channel(chan, 0); diff --git a/src/mod/channels.mod/userchan.c b/src/mod/channels.mod/userchan.c index 74452de8b..dbb1d2f03 100644 --- a/src/mod/channels.mod/userchan.c +++ b/src/mod/channels.mod/userchan.c @@ -43,8 +43,7 @@ static struct chanuserrec *add_chanrec(struct userrec *u, char *chname) ch->flags = 0; ch->flags_udef = 0; ch->laston = 0; - strncpy(ch->channel, chname, 81); - ch->channel[80] = 0; + strlcpy(ch->channel, chname, sizeof ch->channel); if (!noshare && !(u->flags & USER_UNSHARED)) shareout(findchan_by_dname(chname), "+cr %s %s\n", u->handle, chname); } diff --git a/src/mod/irc.mod/chan.c b/src/mod/irc.mod/chan.c index f36381f72..9e492b3bd 100644 --- a/src/mod/irc.mod/chan.c +++ b/src/mod/irc.mod/chan.c @@ -28,7 +28,7 @@ static time_t last_ctcp = (time_t) 0L; static int count_ctcp = 0; static time_t last_invtime = (time_t) 0L; -static char last_invchan[300] = ""; +static char last_invchan[CHANNELLEN + 1] = ""; /* ID length for !channels. */ @@ -1510,8 +1510,7 @@ static int gotinvite(char *from, char *msg) if (now - last_invtime < 30) return 0; /* Two invites to the same channel in 30 seconds? */ putlog(LOG_MISC, "*", "%s!%s invited me to %s", nick, from, msg); - strncpy(last_invchan, msg, 299); - last_invchan[299] = 0; + strlcpy(last_invchan, msg, sizeof last_invchan); last_invtime = now; chan = findchan(msg); if (!chan) @@ -1818,8 +1817,7 @@ static int gotjoin(char *from, char *chname) /* It was me joining! Need to update the channel record with the * unique name for the channel (as the server see's it). */ - strncpy(chan->name, chname, 81); - chan->name[80] = 0; + strlcpy(chan->name, chname, sizeof chan->name); chan->status &= ~CHAN_JUPED; /* ... and log us joining. Using chan->dname for the channel is diff --git a/src/tcldcc.c b/src/tcldcc.c index 48a095775..416a7ecc1 100644 --- a/src/tcldcc.c +++ b/src/tcldcc.c @@ -304,7 +304,7 @@ static int tcl_do_console(Tcl_Interp *irp, ClientData cd, int argc, Tcl_AppendResult(irp, "invalid channel", NULL); return TCL_ERROR; } - strlcpy(dcc[i].u.chat->con_chan, argv[arg], 81); + strlcpy(dcc[i].u.chat->con_chan, argv[arg], sizeof dcc[i].u.chat->con_chan); } else { if (!reset && (argv[arg][0] != '+') && (argv[arg][0] != '-')) dcc[i].u.chat->con_flags = 0; diff --git a/src/users.h b/src/users.h index a0ff02047..92ceadbc8 100644 --- a/src/users.h +++ b/src/users.h @@ -145,7 +145,7 @@ int set_user(struct user_entry_type *, struct userrec *, void *); */ struct chanuserrec { struct chanuserrec *next; - char channel[81]; + char channel[CHANNELLEN + 1]; time_t laston; unsigned long flags; unsigned long flags_udef;