[distcache-users] A defect in distcache 1.5.1
Brought to you by:
geoffthorpe
|
From: Priit R. <pri...@se...> - 2005-11-01 09:26:24
|
Hello,
While writing a squid authentication module (pin-calc with limited
lifetime one-time passwords) which supports sharing user authentication
status
within squid cluster (using distcache, of course ;-)) I found out that
when I created distcache sessions with timeout of 10 hours,
these sessions would be removed by dc_server in 1640 seconds instead. I
took a look at the source and spotted following problem in distcache 1.5.1
libsys/sys.c:
---------------------------
int SYS_expirycheck(const struct timeval *timeitem, unsigned long
msec_expiry,
const struct timeval *timenow)
{
struct timeval threshold;
unsigned long usec_expiry = msec_expiry * 1000;
<-------------- When using timeouts long enough (>4294 seconds), this
will overflow.
SYS_memcpy(struct timeval, &threshold, timeitem);
threshold.tv_sec = threshold.tv_sec + (usec_expiry / 1000000L);
threshold.tv_usec += (usec_expiry % 1000000);
if(threshold.tv_usec > 1000000) {
threshold.tv_usec -= 1000000;
threshold.tv_sec++;
}
if(timercmp(timenow, &threshold, <))
return 0;
return 1;
}
--------------------------------
Maybe this function should look something like this instead?
int SYS_expirycheck(const struct timeval *timeitem, unsigned long
msec_expiry,
const struct timeval *timenow)
{
struct timeval threshold;
SYS_memcpy(struct timeval, &threshold, timeitem);
threshold.tv_sec = threshold.tv_sec + (msec_expiry / 1000);
threshold.tv_usec += (msec_expiry % 1000) * 1000;
if(threshold.tv_usec > 1000000) {
threshold.tv_usec -= 1000000;
threshold.tv_sec++;
}
if(timercmp(timenow, &threshold, <))
/* Not expired yet */
return 0;
/* Expired */
return 1;
}
Regards,
Priit
|