forked from SEU-SSH/skyfish
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharness.c
More file actions
71 lines (62 loc) · 1.72 KB
/
Copy pathharness.c
File metadata and controls
71 lines (62 loc) · 1.72 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
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <errno.h>
void run_pdftotext(const char *program, const char *input, const char *output) {
pid_t pid = fork();
if (pid == 0) {
execl(program, program, input, output, NULL);
fprintf(stderr, "execl failed: %s\n", strerror(errno));
exit(1);
} else if (pid > 0) {
int status;
waitpid(pid, &status, 0);
} else {
perror("fork");
exit(1);
}
}
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <input_file>\n", argv[0]);
return 1;
}
const char *input = argv[1];
const char *output0 = "output0.txt";
const char *output3 = "output3.txt";
// 运行两个版本的pdftotext
run_pdftotext("./benchmark/xpdf_o0/pdftotext", input, output0);
run_pdftotext("./benchmark/xpdf_o3/pdftotext", input, output3);
// 比较输出文件
FILE *f0 = fopen(output0, "r");
FILE *f3 = fopen(output3, "r");
if (!f0 || !f3) {
if (f0) fclose(f0);
if (f3) fclose(f3);
return 0;
}
int diff = 0;
char buf0[4096], buf3[4096];
size_t n0, n3;
do {
n0 = fread(buf0, 1, sizeof(buf0), f0);
n3 = fread(buf3, 1, sizeof(buf3), f3);
if (n0 != n3 || memcmp(buf0, buf3, n0) != 0) {
diff = 1;
break;
}
} while (n0 > 0);
fclose(f0);
fclose(f3);
// 输出不同时保存输入并触发崩溃
if (diff) {
char cmd[1024];
snprintf(cmd, sizeof(cmd), "cp '%s' ./differences/", input);
system(cmd);
abort(); // 触发AFL++记录为crash
}
return 0;
}