-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2038.c
74 lines (63 loc) · 2.02 KB
/
2038.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
__attribute__((constructor)) void flush_buf() {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
}
void print_flag() {
FILE* flag_file;
char c;
flag_file = fopen("flag.txt", "r");
if (flag_file != NULL) {
while ((c = getc(flag_file)) != EOF) {
printf("%c", c);
}
printf("\n");
}
else {
printf("Could not find flag.txt\n");
}
}
int main() {
char time_str[12];
int time_input;
time_t x;
time_t current_time;
// print task
printf("Task: 'print_flag'\n");
printf("Description: 'prints out the flag'\n");
printf("Date: 'undefined'\n\n");
printf("ERROR - date for 'print_flag' task is not defined\n");
printf("This task is not available until January 1st, 2024\n\n");
printf("You may optionally extend this task to be available later\n");
printf("To specify when you would like to make the task available, specify the number of seconds since January 1st, 1970 UTC\n");
// get input
printf("> ");
scanf("%10s", &time_str);
// check that the number of seconds isn't before January 1st, 2024
time_input = atoi(time_str);
if ((unsigned) time_input < 1704067200) {
printf("\nERROR - date must be after January 1st, 2024\n");
return 1;
}
// convert to time and print
x = (time_t)(time_input);
printf("\nSpecified datetime - %s\n", ctime(&x));
// get current time and print
current_time = time(NULL);
printf("Current datetime - %s\n", ctime(¤t_time));
// check if the specified time is before the current time, and if so print the flag (time > 2147483647 will work)
if (x < current_time) {
printf("Time requirement has been met. Running 'print_flag'...\n");
print_flag();
}
else {
printf("'print_flag' was not run because specified date has not occurred yet. Exiting...\n");
}
sleep(1);
return 0;
}