Permalink
Browse files

Fix shared userfile missing first 511 bytes when using SSL

Found by: Geo
Patch by: Cizzle

Fixes sharing of a userfile with SSL which would stall with 511 bytes missing (as could be seen in .dccstat output) and eventually fail. Racing condition where the ssl handshake was finished between the check and reading from the socket, leaving a flag active that treated the data as garbage.
  • Loading branch information...
Cizzle authored and vanosg committed Dec 12, 2017
1 parent c57388c commit 1af4255e87fa0bfe87b209867b19a068823a1f17
Showing with 14 additions and 4 deletions.
  1. +2 −0 src/main.c
  2. +4 −0 src/mod/transfer.mod/transfer.c
  3. +8 −4 src/net.c
View
@@ -869,6 +869,8 @@ int mainloop(int toplevel)
itraffic_dcc_today += strlen(buf) + 1;
else if (!strcmp(dcc[idx].type->name, "SEND"))
itraffic_trans_today += strlen(buf) + 1;
else if (!strcmp(dcc[idx].type->name, "FORK_SEND"))
itraffic_trans_today += strlen(buf) + 1;
else if (!strncmp(dcc[idx].type->name, "GET", 3))
itraffic_trans_today += strlen(buf) + 1;
else
@@ -859,6 +859,10 @@ static void dcc_fork_send(int idx, char *x, int y)
egg_snprintf(s1, sizeof s1, "%s!%s", dcc[idx].nick, dcc[idx].host);
putlog(LOG_MISC, "*", TRANSFER_DCC_CONN, dcc[idx].u.xfer->origname, s1);
}
if (dcc[idx].type->activity && y) {
/* Could already have data! */
dcc[idx].type->activity(idx, x, y);
}
}
static void dcc_get_pending(int idx, char *buf, int len)
View
@@ -1051,6 +1051,12 @@ int sockgets(char *s, int *len)
s[0] = 0;
return ret;
}
/* sockread can return binary data while socket still has connectflag, process first */
if (socklist[ret].flags & SOCK_BINARY && *len > 0) {
socklist[ret].flags &= ~SOCK_CONNECT;
egg_memcpy(s, xx, *len);
return socklist[ret].sock;
}
/* Binary, listening and passed on sockets don't get buffered. */
if (socklist[ret].flags & SOCK_CONNECT) {
if (socklist[ret].flags & SOCK_STRONGCONN) {
@@ -1066,10 +1072,6 @@ int sockgets(char *s, int *len)
s[0] = 0;
return socklist[ret].sock;
}
if (socklist[ret].flags & SOCK_BINARY) {
egg_memcpy(s, xx, *len);
return socklist[ret].sock;
}
if (socklist[ret].flags & (SOCK_LISTEN | SOCK_PASS | SOCK_TCL)) {
s[0] = 0; /* for the dcc traffic counters in the mainloop */
return socklist[ret].sock;
@@ -1188,6 +1190,8 @@ void tputs(register int z, char *s, unsigned int len)
otraffic_filesys_today += len;
else if (!strcmp(dcc[idx].type->name, "SEND"))
otraffic_trans_today += len;
else if (!strcmp(dcc[idx].type->name, "FORK_SEND"))
otraffic_trans_today += len;
else if (!strncmp(dcc[idx].type->name, "GET", 3))
otraffic_trans_today += len;
else

0 comments on commit 1af4255

Please sign in to comment.