Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/time: validate time passed to settimeofday #329

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions sys/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,25 @@ int stime(const time_t *t)

int settimeofday(const struct timeval *tv, void *tz)
{
time_t t;
/* NOTE: tz is ignored here */

/* TODO: Set errno if failed */
gettime(&t, NULL);
if ((tv->tv_usec < 0) || (tv->tv_usec >= (1000 * 1000))) {
return SET_ERRNO(-EINVAL);
}

/* TODO: Set errno if failed */
settime(tv->tv_usec + tv->tv_sec * 1000 * 1000 - t);
time_t bootTimeUs;
gettime(&bootTimeUs, NULL);

return 0;
/* TODO: define max allowed time value to ensure conversions will not overflow */
time_t epochTimeUs = tv->tv_usec + tv->tv_sec * 1000 * 1000;

/* time of boot needs to be after UNIX epoch */
if (bootTimeUs > epochTimeUs) {
return SET_ERRNO(-EINVAL);
}

settime(epochTimeUs - bootTimeUs);
return EOK;
}


Expand Down
Loading