Fix a kernel panic in case when the incorrect of seconds specified for settimeofday() and clock_settime() system calls.
Details
- Reviewers
kib mav - Group Reviewers
manpages - Commits
- rS292777: Verify that tv_sec value specified in settimeofday() and clock_settime()
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
struct timeval now;
struct timeval was;
int rc;
rc = gettimeofday(&was, NULL);
if (rc != 0) {
printf("gettimeofday() failed, errno = %d\n", errno); return (-1);
}
now.tv_sec = -11111111111111;
now.tv_usec = 290944;
rc = settimeofday(&now, NULL);
if (rc == 0)
printf("settimeofday() successful.\n");
else {
printf("settimeofday() failed, errno = %d\n", errno); return (-1);
}
rc = settimeofday(&was, NULL);
return (0);
}
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Passed - Unit
No Test Coverage - Build Status
Buildable 1840 Build 1847: arc lint + arc unit
Event Timeline
Well, as the immediate relief, the change is fine. But the real cause is in clock_ts_to_ct(), I think.
sys/kern/kern_time.c | ||
---|---|---|
401 | Style: put '||' at the first if() line, we usually split long lines after the operator, not before. |
Thank you, Kostya!
I think that clock_ts_to_ct() should be rewritten to correctly handle the negative tv_sec value.
But by design settimeofday() and clock_settime() is not intended to take negative tv_sec, is why I suggest this fix.