Skip to content

Commit 6bc6560

Browse files
Fix hangs on some SSL connections
Found by: pym67, @PeGaSuS-Coder Patch by: michaelortmann Fixes: #1496 This PR fixes Eggdrop hanging on some socket connections by upping the read buffer size for SSL_read() and read() to 16K, the maximum according to SSL spec and to openssls internal buffer size. It may also help resolve some hanging userfile transfers.
1 parent b774e92 commit 6bc6560

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

src/Makefile.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ modules.o: modules.c main.h ../config.h ../eggint.h ../lush.h lang.h \
174174
net.o: net.c main.h ../config.h ../eggint.h ../lush.h lang.h eggdrop.h \
175175
compat/in6.h flags.h proto.h misc_file.h cmdt.h tclegg.h tclhash.h \
176176
chan.h users.h compat/compat.h compat/base64.h compat/inet_aton.h \
177-
../src/main.h compat/snprintf.h compat/explicit_bzero.h compat/strlcpy.h \
178-
mod/server.mod/server.h
177+
../src/main.h compat/snprintf.h compat/explicit_bzero.h compat/strlcpy.h
179178
rfc1459.o: rfc1459.c main.h ../config.h ../eggint.h ../lush.h lang.h \
180179
eggdrop.h compat/in6.h flags.h proto.h misc_file.h cmdt.h tclegg.h \
181180
tclhash.h chan.h users.h compat/compat.h compat/base64.h \

src/eggdrop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#define UHOSTMAX 291 + NICKMAX /* 32 (ident) + 3 (\0, !, @) + NICKMAX */
6161
#define DIRMAX 512 /* paranoia */
6262
#define LOGLINEMAX 9000 /* for misc.c/putlog() <cybah> */
63+
#define READMAX 16384 /* for read() and SSL_read() */
6364

6465
/* Invalid characters */
6566
#define BADHANDCHARS "-,+*=:!.@#;$%&"

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ static void mainloop(int toplevel)
787787
{
788788
static int cleanup = 5;
789789
int xx, i, eggbusy = 1;
790-
char buf[8702];
790+
char buf[READMAX + 2];
791791

792792
/* Lets move some of this here, reducing the number of actual
793793
* calls to periodic_timers

src/net.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
# include <unistd.h>
4343
#endif
4444
#include <setjmp.h>
45-
#include "mod/server.mod/server.h"
4645

4746
#ifdef TLS
4847
# include <openssl/err.h>
@@ -894,7 +893,7 @@ int sockread(char *s, int *len, sock_list *slist, int slistmax, int tclonly)
894893
struct timeval t;
895894
fd_set fdr, fdw, fde;
896895
int i, x, maxfd_r, maxfd_w, maxfd_e;
897-
int grab = 511, tclsock = -1, events = 0;
896+
int grab = READMAX, tclsock = -1, events = 0;
898897
struct threaddata *td = threaddata();
899898
int maxfd;
900899
#ifdef EGG_TDNS
@@ -938,8 +937,7 @@ int sockread(char *s, int *len, sock_list *slist, int slistmax, int tclonly)
938937
if (!tclonly && ((!(slist[i].flags & (SOCK_UNUSED | SOCK_TCL))) &&
939938
((FD_ISSET(slist[i].sock, &fdr)) ||
940939
#ifdef TLS
941-
(slist[i].ssl && (SSL_pending(slist[i].ssl) ||
942-
!SSL_is_init_finished(slist[i].ssl))) ||
940+
(slist[i].ssl && !SSL_is_init_finished(slist[i].ssl)) ||
943941
#endif
944942
((slist[i].sock == STDOUT) && (!backgrd) &&
945943
(FD_ISSET(STDIN, &fdr)))))) {
@@ -1102,7 +1100,7 @@ int sockread(char *s, int *len, sock_list *slist, int slistmax, int tclonly)
11021100

11031101
int sockgets(char *s, int *len)
11041102
{
1105-
char xx[RECVLINEMAX], *p, *px, *p2;
1103+
char xx[READMAX + 2], *p, *px, *p2;
11061104
int ret, i, data = 0;
11071105
size_t len2;
11081106
struct threaddata *td = threaddata();
@@ -1129,7 +1127,7 @@ int sockgets(char *s, int *len)
11291127
p++;
11301128
*p2 = 0;
11311129

1132-
strlcpy(s, socklist[i].handler.sock.inbuf, RECVLINEMAX-1);
1130+
strlcpy(s, socklist[i].handler.sock.inbuf, READMAX + 1);
11331131
if (*p) {
11341132
len2 = strlen(p) + 1;
11351133
px = nmalloc(len2);
@@ -1145,15 +1143,15 @@ int sockgets(char *s, int *len)
11451143
}
11461144
} else {
11471145
/* Handling buffered binary data (must have been SOCK_BUFFER before). */
1148-
if (socklist[i].handler.sock.inbuflen <= RECVLINEMAX-2) {
1146+
if (socklist[i].handler.sock.inbuflen <= READMAX) {
11491147
*len = socklist[i].handler.sock.inbuflen;
11501148
memcpy(s, socklist[i].handler.sock.inbuf, socklist[i].handler.sock.inbuflen);
11511149
nfree(socklist[i].handler.sock.inbuf);
11521150
socklist[i].handler.sock.inbuf = NULL;
11531151
socklist[i].handler.sock.inbuflen = 0;
11541152
} else {
1155-
/* Split up into chunks of RECVLINEMAX-2 bytes. */
1156-
*len = RECVLINEMAX-2;
1153+
/* Split up into chunks of READMAX bytes. */
1154+
*len = READMAX;
11571155
memcpy(s, socklist[i].handler.sock.inbuf, *len);
11581156
memcpy(socklist[i].handler.sock.inbuf, socklist[i].handler.sock.inbuf + *len, *len);
11591157
socklist[i].handler.sock.inbuflen -= *len;
@@ -1218,17 +1216,17 @@ int sockgets(char *s, int *len)
12181216
strcpy(socklist[ret].handler.sock.inbuf, p);
12191217
strcat(socklist[ret].handler.sock.inbuf, xx);
12201218
nfree(p);
1221-
if (strlen(socklist[ret].handler.sock.inbuf) < RECVLINEMAX) {
1219+
if (strlen(socklist[ret].handler.sock.inbuf) < READMAX + 2) {
12221220
strcpy(xx, socklist[ret].handler.sock.inbuf);
12231221
nfree(socklist[ret].handler.sock.inbuf);
12241222
socklist[ret].handler.sock.inbuf = NULL;
12251223
socklist[ret].handler.sock.inbuflen = 0;
12261224
} else {
12271225
p = socklist[ret].handler.sock.inbuf;
1228-
socklist[ret].handler.sock.inbuflen = strlen(p) - RECVLINEMAX-2;
1226+
socklist[ret].handler.sock.inbuflen = strlen(p) - READMAX;
12291227
socklist[ret].handler.sock.inbuf = nmalloc(socklist[ret].handler.sock.inbuflen + 1);
1230-
strcpy(socklist[ret].handler.sock.inbuf, p + RECVLINEMAX-2);
1231-
*(p + RECVLINEMAX-2) = 0;
1228+
strcpy(socklist[ret].handler.sock.inbuf, p + READMAX);
1229+
*(p + READMAX) = 0;
12321230
strcpy(xx, p);
12331231
nfree(p);
12341232
/* (leave the rest to be post-pended later) */
@@ -1249,7 +1247,7 @@ int sockgets(char *s, int *len)
12491247
/* if (!s[0]) strcpy(s," "); */
12501248
if (!data) {
12511249
s[0] = 0;
1252-
if (strlen(xx) >= RECVLINEMAX-2) {
1250+
if (strlen(xx) >= READMAX) {
12531251
/* String is too long, so just insert fake \n */
12541252
strcpy(s, xx);
12551253
xx[0] = 0;

0 commit comments

Comments
 (0)