Skip to content

Commit 5d5d6bc

Browse files
authored
Add files via upload
1 parent baec186 commit 5d5d6bc

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:12:7:12:12 | call to chroot | Creation of chroot Jail Without Changing Working Directory out |
2+
| test.cpp:29:3:29:7 | call to chdir | chdir unchecked return value. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-243/IncorrectChangingWorkingDirectory.ql
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
typedef int FILE;
2+
#define size_t int
3+
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
4+
FILE *fopen(const char *filename, const char *mode);
5+
int fread(char *buf, int size, int count, FILE *fp);
6+
int fclose(FILE *fp);
7+
int chroot(char *path);
8+
int chdir(char *path);
9+
void exit(int status);
10+
11+
int funTest1(){
12+
if (chroot("/myFold/myTmp") == -1) { // BAD
13+
exit(-1);
14+
}
15+
return 0;
16+
}
17+
18+
int funTest2(){
19+
if (chdir("/myFold/myTmp") == -1) { // GOOD
20+
exit(-1);
21+
}
22+
if (chroot("/myFold/myTmp") == -1) { // GOOD
23+
exit(-1);
24+
}
25+
return 0;
26+
}
27+
28+
int funTest3(){
29+
chdir("/myFold/myTmp"); // BAD
30+
return 0;
31+
}
32+
int main(int argc, char *argv[])
33+
{
34+
if(argc = 0) {
35+
funTest3();
36+
return 2;
37+
}
38+
if(argc = 1)
39+
funTest1();
40+
else
41+
funTest2();
42+
FILE *fp = fopen(argv[1], "w");
43+
fwrite("12345", 5, 1, fp);
44+
fclose(fp);
45+
return 0;
46+
}

0 commit comments

Comments
 (0)