Skip to content

Commit

Permalink
samples/gettimeofday: Detect 32-bit timeval.tv_sec
Browse files Browse the repository at this point in the history
Check to make sure the target is not using 32-bit time_t values which would
leave the application vulnerable to 2038 bugs.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Sep 30, 2023
1 parent af7f98e commit 0bd5beb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions samples/posix/gettimeofday/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ int main(void)
{
struct timeval tv;

if (sizeof(tv.tv_sec) < 8) {
printf("Error: sizeof(time_t) (%d) is less than 64 bits\n",
(int) sizeof(tv.tv_sec));
return 1;
}

while (1) {
int res = gettimeofday(&tv, NULL);
time_t now = time(NULL);
Expand Down

0 comments on commit 0bd5beb

Please sign in to comment.