Skip to content
Permalink
Browse files

Update buffer sizes to accomodate larger msgtag strings

  • Loading branch information
vanosg committed Jan 8, 2020
1 parent 75d4803 commit 12289dc58bc10dbedb57c57900a68a89fd89152c
Showing with 31 additions and 27 deletions.
  1. +6 −6 src/dccutil.c
  2. +1 −1 src/eggdrop.h
  3. +1 −1 src/main.c
  4. +2 −2 src/misc.c
  5. +7 −6 src/mod/server.mod/server.c
  6. +2 −0 src/mod/server.mod/servmsg.c
  7. +1 −1 src/mod/server.mod/tclserv.c
  8. +11 −10 src/net.c
@@ -151,15 +151,15 @@ extern void (*qserver) (int, char *, int);

void dprintf EGG_VARARGS_DEF(int, arg1)
{
char buf[1024];
char buf[LOGLINEMAX];
char *format;
int idx, len;
va_list va;

idx = EGG_VARARGS_START(int, arg1, va);
format = va_arg(va, char *);

egg_vsnprintf(buf, 1023, format, va);
egg_vsnprintf(buf, LOGLINEMAX-1, format, va);
va_end(va);
/* We can not use the return value vsnprintf() to determine where
* to null terminate. The C99 standard specifies that vsnprintf()
@@ -202,10 +202,10 @@ void dprint(int idx, char *buf, int len)
}
return;
} else {
if (len > 500) { /* Truncate to fit */
buf[500] = '\n';
buf[501] = 0;
len = 501;
if (len > LOGLINEMAX-11) { /* Truncate to fit */
buf[LOGLINEMAX-11] = '\n';
buf[LOGLINEMAX-10] = 0;
len = LOGLINEMAX-10;
}
if (dcc[idx].type && ((long) (dcc[idx].type->output) == 1)) {
char *p = add_cr(buf);
@@ -58,7 +58,7 @@
/* Handy string lengths */
#define UHOSTMAX 291 + NICKMAX /* 32 (ident) + 3 (\0, !, @) + NICKMAX */
#define DIRMAX 512 /* paranoia */
#define LOGLINEMAX 767 /* for misc.c/putlog() <cybah> */
#define LOGLINEMAX 9000 /* for misc.c/putlog() <cybah> */

/* Invalid characters */
#define BADNICKCHARS "-,+*=:!.@#;$%&"
@@ -803,7 +803,7 @@ int mainloop(int toplevel)
{
static int socket_cleanup = 0;
int xx, i, eggbusy = 1, tclbusy = 0;
char buf[520];
char buf[8702];

/* Lets move some of this here, reducing the number of actual
* calls to periodic_timers
@@ -517,12 +517,12 @@ void putlog EGG_VARARGS_DEF(int, arg1)
{
static int inhere = 0;
int i, type, tsl = 0;
char *format, *chname, s[LOGLINELEN], s1[256], *out, ct[81], *s2, stamp[34];
char *format, *chname, s[LOGLINELEN], s1[LOGLINELEN], *out, ct[81], *s2, stamp[34];
va_list va;
time_t now2 = time(NULL);
static time_t now2_last = 0; /* cache expensive localtime() */
static struct tm *t;

if (now2 != now2_last) {
now2_last = now2;
t = localtime(&now2);
@@ -437,8 +437,9 @@ static int fast_deq(int which)
{
struct msgq_head *h;
struct msgq *m, *nm;
char msgstr[MSGMAX], nextmsgstr[MSGMAX], tosend[MSGMAX], victims[MSGMAX], stackable[MSGMAX],
*msg, *nextmsg, *cmd, *nextcmd, *to, *nextto, *stckbl;
char msgstr[SENDLINEMAX], nextmsgstr[SENDLINEMAX], tosend[SENDLINEMAX],
victims[SENDLINEMAX], stackable[SENDLINEMAX], *msg, *nextmsg, *cmd,
*nextcmd, *to, *nextto, *stckbl;
int len, doit = 0, found = 0, cmd_count = 0, stack_method = 1;

if (!use_fastdeq)
@@ -501,7 +502,7 @@ static int fast_deq(int which)
nextto = newsplit(&nextmsg);
if (strcmp(to, nextto) && !strcmp(cmd, nextcmd) && !strcmp(msg, nextmsg) &&
((strlen(cmd) + strlen(victims) + strlen(nextto) + strlen(msg) + 2) <
510) && (!stack_limit || cmd_count < stack_limit - 1)) {
SENDLINEMAX-2) && (!stack_limit || cmd_count < stack_limit - 1)) {
cmd_count++;
if (stack_method == 1)
simple_sprintf(victims, "%s,%s", victims, nextto);
@@ -563,7 +564,7 @@ static void check_queues(char *oldnick, char *newnick)
static void parse_q(struct msgq_head *q, char *oldnick, char *newnick)
{
struct msgq *m, *lm = NULL;
char buf[MSGMAX], *msg, *nicks, *nick, *chan, newnicks[MSGMAX], newmsg[MSGMAX];
char buf[SENDLINEMAX], *msg, *nicks, *nick, *chan, newnicks[SENDLINEMAX], newmsg[SENDLINEMAX];
int changed;

for (m = q->head; m;) {
@@ -579,7 +580,7 @@ static void parse_q(struct msgq_head *q, char *oldnick, char *newnick)
nick = splitnicks(&nicks);
if (!strcasecmp(nick, oldnick) &&
((9 + strlen(chan) + strlen(newnicks) + strlen(newnick) +
strlen(nicks) + strlen(msg)) < 510)) {
strlen(nicks) + strlen(msg)) < SENDLINEMAX-1)) {
if (newnick)
egg_snprintf(newnicks, sizeof newnicks, "%s,%s", newnicks, newnick);
changed = 1;
@@ -828,7 +829,7 @@ static void queue_server(int which, char *msg, int len)
struct msgq_head *h = NULL, tempq;
struct msgq *q, *tq, *tqq;
int doublemsg = 0, qnext = 0;
char buf[MSGMAX];
char buf[SENDLINEMAX];

/* Don't even BOTHER if there's no server online. */
if (serv < 0)
@@ -1168,6 +1168,8 @@ static void server_activity(int idx, char *tagmsg, int len)
} else {
check_tcl_raw(from, code, msgptr);
}
// check_tcl_rawt(from, code, msgptr, tagdict);
// check_tcl_raw(from, code, msgptr);
}

static int gotping(char *from, char *msg)
@@ -164,7 +164,7 @@ static int tcl_puthelp STDVAR

/* Send a msg to the server prefixed with an IRCv3 message-tag */
static int tcl_tagmsg STDVAR {
char tag[TAGMAX];
char tag[CLITAGMAX];
char target[MSGMAX];
char *p;
BADARGS(3, 3, " tag target");
@@ -42,6 +42,7 @@
# include <unistd.h>
#endif
#include <setjmp.h>
#include "mod/server.mod/server.h"

#ifdef TLS
# include <openssl/err.h>
@@ -1050,7 +1051,7 @@ int sockread(char *s, int *len, sock_list *slist, int slistmax, int tclonly)

int sockgets(char *s, int *len)
{
char xx[514], *p, *px;
char xx[RECVLINEMAX], *p, *px;
int ret, i, data = 0;
size_t len2;

@@ -1067,7 +1068,7 @@ int sockgets(char *s, int *len)
*p++ = 0;
while (*p == '\n' || *p == '\r')
p++;
strlcpy(s, socklist[i].handler.sock.inbuf, 511);
strlcpy(s, socklist[i].handler.sock.inbuf, RECVLINEMAX-1);
if (*p) {
len2 = strlen(p) + 1;
px = nmalloc(len2);
@@ -1083,15 +1084,15 @@ int sockgets(char *s, int *len)
}
} else {
/* Handling buffered binary data (must have been SOCK_BUFFER before). */
if (socklist[i].handler.sock.inbuflen <= 510) {
if (socklist[i].handler.sock.inbuflen <= RECVLINEMAX-2) {
*len = socklist[i].handler.sock.inbuflen;
memcpy(s, socklist[i].handler.sock.inbuf, socklist[i].handler.sock.inbuflen);
nfree(socklist[i].handler.sock.inbuf);
socklist[i].handler.sock.inbuf = NULL;
socklist[i].handler.sock.inbuflen = 0;
} else {
/* Split up into chunks of 510 bytes. */
*len = 510;
/* Split up into chunks of RECVLINEMAX-2 bytes. */
*len = RECVLINEMAX-2;
memcpy(s, socklist[i].handler.sock.inbuf, *len);
memcpy(socklist[i].handler.sock.inbuf, socklist[i].handler.sock.inbuf + *len, *len);
socklist[i].handler.sock.inbuflen -= *len;
@@ -1156,17 +1157,17 @@ int sockgets(char *s, int *len)
strcpy(socklist[ret].handler.sock.inbuf, p);
strcat(socklist[ret].handler.sock.inbuf, xx);
nfree(p);
if (strlen(socklist[ret].handler.sock.inbuf) < 512) {
if (strlen(socklist[ret].handler.sock.inbuf) < RECVLINEMAX) {
strcpy(xx, socklist[ret].handler.sock.inbuf);
nfree(socklist[ret].handler.sock.inbuf);
socklist[ret].handler.sock.inbuf = NULL;
socklist[ret].handler.sock.inbuflen = 0;
} else {
p = socklist[ret].handler.sock.inbuf;
socklist[ret].handler.sock.inbuflen = strlen(p) - 510;
socklist[ret].handler.sock.inbuflen = strlen(p) - RECVLINEMAX-2;
socklist[ret].handler.sock.inbuf = nmalloc(socklist[ret].handler.sock.inbuflen + 1);
strcpy(socklist[ret].handler.sock.inbuf, p + 510);
*(p + 510) = 0;
strcpy(socklist[ret].handler.sock.inbuf, p + RECVLINEMAX-2);
*(p + RECVLINEMAX-2) = 0;
strcpy(xx, p);
nfree(p);
/* (leave the rest to be post-pended later) */
@@ -1187,7 +1188,7 @@ int sockgets(char *s, int *len)
/* if (!s[0]) strcpy(s," "); */
if (!data) {
s[0] = 0;
if (strlen(xx) >= 510) {
if (strlen(xx) >= RECVLINEMAX-2) {
/* String is too long, so just insert fake \n */
strcpy(s, xx);
xx[0] = 0;

0 comments on commit 12289dc

Please sign in to comment.
You can’t perform that action at this time.