If multiple accept's happen during a select, make sure it gets stored correctly, and does not clobber an existing open descriptor.
Signed-off-by: Love Hörnquist Åstrand <lha@h5l.org>
This commit is contained in:

committed by
Love Hörnquist Åstrand

parent
3ea8da179a
commit
3f71aca591
@@ -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
|
void
|
||||||
loop(krb5_context context,
|
loop(krb5_context context,
|
||||||
krb5_kdc_configuration *config)
|
krb5_kdc_configuration *config)
|
||||||
@@ -862,22 +904,6 @@ loop(krb5_context context,
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
FD_SET(d[i].s, &fds);
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,10 +919,12 @@ loop(krb5_context context,
|
|||||||
default:
|
default:
|
||||||
for(i = 0; i < ndescr; i++)
|
for(i = 0; i < ndescr; i++)
|
||||||
if(!rk_IS_BAD_SOCKET(d[i].s) && FD_ISSET(d[i].s, &fds)) {
|
if(!rk_IS_BAD_SOCKET(d[i].s) && FD_ISSET(d[i].s, &fds)) {
|
||||||
if(d[i].type == SOCK_DGRAM)
|
min_free = next_min_free(context, &d, &ndescr);
|
||||||
handle_udp(context, config, &d[i]);
|
|
||||||
else if(d[i].type == SOCK_STREAM)
|
if(d[i].type == SOCK_DGRAM)
|
||||||
handle_tcp(context, config, d, i, min_free);
|
handle_udp(context, config, &d[i]);
|
||||||
|
else if(d[i].type == SOCK_STREAM)
|
||||||
|
handle_tcp(context, config, d, i, min_free);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user