Description: Adjust starttime test when run under Debian faketime
Author: Todd C. Miller <Todd.Miller@sudo.ws>
Bug: https://bugzilla.sudo.ws/show_bug.cgi?id=1026
--- a/include/sudo_util.h
+++ b/include/sudo_util.h
@@ -33,6 +33,13 @@
 #endif
 #define ROOT_GID	0
 
+#ifndef TIME_T_MIN
+# if SIZEOF_TIME_T == 8
+#  define TIME_T_MIN	LLONG_MIN
+# else
+#  define TIME_T_MIN	INT_MIN
+# endif
+#endif
 #ifndef TIME_T_MAX
 # if SIZEOF_TIME_T == 8
 #  define TIME_T_MAX	LLONG_MAX
--- a/plugins/sudoers/regress/starttime/check_starttime.c
+++ b/plugins/sudoers/regress/starttime/check_starttime.c
@@ -80,7 +80,9 @@ main(int argc, char *argv[])
 {
     int ntests = 0, errors = 0;
     struct timespec now, then, delta;
+    time_t timeoff = 0;
     pid_t pids[2];
+    char *faketime;
     int i;
 
     initprogname(argc > 0 ? argv[0] : "check_starttime");
@@ -91,6 +93,11 @@ main(int argc, char *argv[])
     pids[0] = getpid();
     pids[1] = getppid();
 
+    /* Debian CI pipeline runs tests using faketime. */
+    faketime = getenv("FAKETIME");
+    if (faketime != NULL)
+	timeoff = sudo_strtonum(faketime, TIME_T_MIN, TIME_T_MAX, NULL);
+
     for (i = 0; i < 2; i++) {
 	ntests++;
 	if (get_starttime(pids[i], &then)  == -1) {
@@ -104,6 +111,7 @@ main(int argc, char *argv[])
 	/* Verify our own process start time, allowing for some drift. */
 	ntests++;
 	sudo_timespecsub(&then, &now, &delta);
+	delta.tv_sec += timeoff;
 	if (delta.tv_sec > 30 || delta.tv_sec < -30) {
 	    printf("%s: test %d: unexpected start time for pid %d: %s",
 		getprogname(), ntests, (int)pids[i], ctime(&then.tv_sec));
