Mercurial > dropbear
comparison dbutil.c @ 1375:d8215479a58a fuzz
fuzzing has a constant time
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 25 May 2017 22:20:10 +0800 |
parents | ddfcadca3c4c |
children | f03cfe9c76ac |
comparison
equal
deleted
inserted
replaced
1374:4b1a807a3188 | 1375:d8215479a58a |
---|---|
623 return -1; | 623 return -1; |
624 } | 624 } |
625 #endif | 625 #endif |
626 | 626 |
627 time_t monotonic_now() { | 627 time_t monotonic_now() { |
628 #ifdef DROPBEAR_FUZZ | |
629 if (fuzz.fuzzing) { | |
630 /* time stands still when fuzzing */ | |
631 return 5; | |
632 } | |
633 #endif | |
628 #if defined(__linux__) && defined(SYS_clock_gettime) | 634 #if defined(__linux__) && defined(SYS_clock_gettime) |
635 { | |
629 static clockid_t clock_source = -2; | 636 static clockid_t clock_source = -2; |
630 | 637 |
631 if (clock_source == -2) { | 638 if (clock_source == -2) { |
632 /* First run, find out which one works. | 639 /* First run, find out which one works. |
633 -1 will fall back to time() */ | 640 -1 will fall back to time() */ |
640 /* Intermittent clock failures should not happen */ | 647 /* Intermittent clock failures should not happen */ |
641 dropbear_exit("Clock broke"); | 648 dropbear_exit("Clock broke"); |
642 } | 649 } |
643 return ts.tv_sec; | 650 return ts.tv_sec; |
644 } | 651 } |
652 } | |
645 #endif /* linux clock_gettime */ | 653 #endif /* linux clock_gettime */ |
646 | 654 |
647 #if defined(HAVE_MACH_ABSOLUTE_TIME) | 655 #if defined(HAVE_MACH_ABSOLUTE_TIME) |
656 { | |
648 /* OS X, see https://developer.apple.com/library/mac/qa/qa1398/_index.html */ | 657 /* OS X, see https://developer.apple.com/library/mac/qa/qa1398/_index.html */ |
649 static mach_timebase_info_data_t timebase_info; | 658 static mach_timebase_info_data_t timebase_info; |
650 if (timebase_info.denom == 0) { | 659 if (timebase_info.denom == 0) { |
651 mach_timebase_info(&timebase_info); | 660 mach_timebase_info(&timebase_info); |
652 } | 661 } |
653 return mach_absolute_time() * timebase_info.numer / timebase_info.denom | 662 return mach_absolute_time() * timebase_info.numer / timebase_info.denom |
654 / 1e9; | 663 / 1e9; |
664 } | |
655 #endif /* osx mach_absolute_time */ | 665 #endif /* osx mach_absolute_time */ |
656 | 666 |
657 /* Fallback for everything else - this will sometimes go backwards */ | 667 /* Fallback for everything else - this will sometimes go backwards */ |
658 return time(NULL); | 668 return time(NULL); |
659 } | 669 } |