-
Notifications
You must be signed in to change notification settings - Fork 26
/
bs.c
70 lines (66 loc) · 1.42 KB
/
bs.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
#include <errno.h>
#include <stdio.h>
#include <pthread.h>
#include <asm/prctl.h>
#include <sys/prctl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
size_t get_long() {
char buf[8];
fgets(buf, 8, stdin);
return (size_t)atol(buf);
}
size_t readn(int fd, char *buf, size_t n) {
size_t rc;
size_t nread = 0;
while (nread < n) {
rc = read(fd, &buf[nread], n-nread);
if (rc == -1) {
if (errno == EAGAIN || errno == EINTR) {
continue;
}
return -1;
}
if (rc == 0) {
break;
}
nread += rc;
}
return nread;
}
void * start() {
size_t size;
char input[0x1000];
memset(input, 0, 0x1000);
puts("Welcome to babystack 2018!");
puts("How many bytes do you want to send?");
size = get_long();
if (size > 0x10000) {
puts("You are greedy!");
return 0;
}
readn(0, input, size);
puts("It's time to say goodbye.");
return 0;
}
int main() {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
pthread_t t;
puts("");
puts(" # # #### ##### ######");
puts(" # # # # # #");
puts("### ### # # #####");
puts(" # # # # #");
puts(" # # # # # #");
puts(" #### # #");
puts("");
pthread_create(&t, NULL, &start, 0);
if (pthread_join(t, NULL) != 0) {
puts("exit failure");
return 1;
}
puts("Bye bye");
return 0;
}