Skip to content

Commit

Permalink
Fix segfault for small max-socks
Browse files Browse the repository at this point in the history
Patch by: michaelortmann
  • Loading branch information
michaelortmann authored and vanosg committed Dec 11, 2018
1 parent 441ce6d commit e9c2478
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/dccutil.c
Expand Up @@ -57,7 +57,7 @@ int max_dcc = 0; /* indicates the current dcc limit in the main thread */
int increase_socks_max() int increase_socks_max()
{ {
struct threaddata *td = threaddata(); struct threaddata *td = threaddata();
int osock = td->MAXSOCKS; int osock = td->MAXSOCKS, max_dcc_new;


if (max_socks < 1) if (max_socks < 1)
max_socks = 1; max_socks = 1;
Expand All @@ -79,9 +79,15 @@ int increase_socks_max()
td->socklist[osock].flags = SOCK_UNUSED; td->socklist[osock].flags = SOCK_UNUSED;


if (td->mainthread) { if (td->mainthread) {
max_dcc = td->MAXSOCKS - 10; max_dcc_new = td->MAXSOCKS - 10;
if (max_dcc < 1) if (max_dcc_new > max_dcc)
max_dcc = 1; max_dcc = max_dcc_new;
else if (max_dcc == 0)
max_dcc = 1;
else {
putlog(LOG_MISC, "*", "Maximum dcc limit reached. Consider raising max-socks.");
return -1;
}
if (dcc) if (dcc)
dcc = nrealloc(dcc, sizeof(struct dcc_t) * max_dcc); dcc = nrealloc(dcc, sizeof(struct dcc_t) * max_dcc);
else else
Expand Down

0 comments on commit e9c2478

Please sign in to comment.