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 Oct 3, 2023
1 parent 9561c1a commit a4dcf3d
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) < sizeof(uint64_t)) {
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 a4dcf3d

Please sign in to comment.