Skip to content

Commit

Permalink
If multiple accept's happen during a select, make sure it gets stored…
Browse files Browse the repository at this point in the history
… correctly, and does not clobber an existing open descriptor.

Signed-off-by: Love Hörnquist Åstrand <lha@h5l.org>
  • Loading branch information
3405691582 authored and Love Hörnquist Åstrand committed Nov 17, 2012
1 parent 3ea8da1 commit 3f71aca
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions kdc/connect.c
Expand Up @@ -824,6 +824,48 @@ handle_tcp(krb5_context context,
}
}

krb5_boolean
realloc_descrs(struct descr **d, unsigned int *ndescr)
{
struct descr *tmp;
size_t i;

tmp = realloc(*d, (*ndescr + 4) * sizeof(**d));
if(tmp == NULL)
return TRUE;

*d = tmp;
reinit_descrs (*d, *ndescr);
memset(*d + *ndescr, 0, 4 * sizeof(**d));
for(i = *ndescr; i < *ndescr + 4; i++)
init_descr (*d + i);

*ndescr += 4;

return FALSE;
}

int
next_min_free(krb5_context context, struct descr **d, unsigned int *ndescr)
{
size_t i;
int min_free;

for(i = 0; i < *ndescr; i++) {
int s = (*d + i)->s;
if(rk_IS_BAD_SOCKET(s))
return i;
}

min_free = *ndescr;
if(!realloc_descrs(d, ndescr)) {
min_free = -1;
krb5_warnx(context, "No memory");
}

return min_free;
}

void
loop(krb5_context context,
krb5_kdc_configuration *config)
Expand Down Expand Up @@ -862,22 +904,6 @@ loop(krb5_context context,
#endif
#endif
FD_SET(d[i].s, &fds);
} else if(min_free < 0 || i < (size_t)min_free)
min_free = i;
}
if(min_free == -1){
struct descr *tmp;
tmp = realloc(d, (ndescr + 4) * sizeof(*d));
if(tmp == NULL)
krb5_warnx(context, "No memory");
else {
d = tmp;
reinit_descrs (d, ndescr);
memset(d + ndescr, 0, 4 * sizeof(*d));
for(i = ndescr; i < ndescr + 4; i++)
init_descr (&d[i]);
min_free = ndescr;
ndescr += 4;
}
}

Expand All @@ -893,10 +919,12 @@ loop(krb5_context context,
default:
for(i = 0; i < ndescr; i++)
if(!rk_IS_BAD_SOCKET(d[i].s) && FD_ISSET(d[i].s, &fds)) {
if(d[i].type == SOCK_DGRAM)
handle_udp(context, config, &d[i]);
else if(d[i].type == SOCK_STREAM)
handle_tcp(context, config, d, i, min_free);
min_free = next_min_free(context, &d, &ndescr);

if(d[i].type == SOCK_DGRAM)
handle_udp(context, config, &d[i]);
else if(d[i].type == SOCK_STREAM)
handle_tcp(context, config, d, i, min_free);
}
}
}
Expand Down

0 comments on commit 3f71aca

Please sign in to comment.