-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeadly_bug1.c
54 lines (41 loc) · 1.04 KB
/
deadly_bug1.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
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#define BUFFER_SIZE 400
#define true 1
#define false 0
char isFileExist(char *filename){
if(access(filename, F_OK) != -1){
return true;
}
else{
return false;
}
}
int main(int argc, char *argv[]){
// first part of file command
char *sys_cmd1 = "cat ";
// second part of file command
char *sys_cmd2 = " | ./kernel/kernel 1";
int sys_cmd1_len = strlen(sys_cmd1);
int sys_cmd2_len = strlen(sys_cmd2);
if (argc == 2)
{
int arg_len = strlen(argv[1]);
int buffer_length = sys_cmd1_len + sys_cmd2_len + arg_len + 1;
char buffer[buffer_length];
if(isFileExist(argv[1]) != true){
printf("No such file\n");
return EXIT_FAILURE;
}
strcpy(buffer, sys_cmd1);
strcat(buffer, argv[1]);
strcat(buffer, sys_cmd2);
system(buffer);
}
else{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}