Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce CHANNELLEN and convert some strncpy + \0 into strlcpy() #567

Merged
merged 11 commits into from
Oct 13, 2018
6 changes: 3 additions & 3 deletions src/chan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
27 changes: 14 additions & 13 deletions src/eggdrop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion src/mod/channels.mod/cmdschan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/mod/channels.mod/tclchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. <cybah>
*/
strncpy(chan->dname, newname, 81);
chan->dname[80] = 0;
strlcpy(chan->dname, newname, sizeof chan->dname);

/* Initialize chan->channel info */
init_channel(chan, 0);
Expand Down
3 changes: 1 addition & 2 deletions src/mod/channels.mod/userchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 3 additions & 5 deletions src/mod/irc.mod/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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). <cybah>
*/
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
Expand Down
2 changes: 1 addition & 1 deletion src/tcldcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/users.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down