forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_workerfs_read.c
More file actions
71 lines (59 loc) · 1.34 KB
/
Copy pathtest_workerfs_read.c
File metadata and controls
71 lines (59 loc) · 1.34 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <emscripten.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#define SECRET_LEN 10
int result = 1;
int main() {
int fd;
int fd2;
struct stat st;
struct stat st2;
char buf[100];
char secret2[] = SECRET2;
int len2 = SECRET_LEN / 2;
if (stat("/work/notexist.txt", &st) != -1 || errno != ENOENT) {
result = -1000 - errno;
goto exit;
}
if (stat("/work/blob.txt", &st) != 0) {
result = -2000 - errno;
goto exit;
}
fd = open("/work/blob.txt", O_RDWR, 0666);
if (fd == -1) {
result = -3000 - errno;
goto exit;
}
if (read(fd, buf, 1000) != SECRET_LEN ||
strncmp(buf, SECRET, SECRET_LEN) != 0) {
result = -4000 - errno;
goto exit;
}
fd2 = open("/work/file.txt", O_RDONLY, 0666);
if (fd == -1) {
result = -5000 - errno;
goto exit;
}
if (lseek(fd2, len2, SEEK_SET) != len2) {
result = -6000 - errno;
goto exit;
}
if (read(fd2, buf, len2) != len2 ||
strncmp(buf, secret2 + len2, len2) != 0) {
result = -7000 - errno;
goto exit;
}
stat("/work/file.txt", &st);
chmod("/work/file.txt", 0640);
stat("/work/file.txt", &st2);
if (st.st_mode != (0777 | S_IFREG) || st2.st_mode != (0640 | S_IFREG)) {
result = -8000 - errno;
goto exit;
}
exit:
REPORT_RESULT();
}