Skip to content

Commit a33c076

Browse files
authored
Add files via upload
1 parent 6173b11 commit a33c076

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:9:3:9:7 | call to umask | not use equal argument in umask and chmod functions |
2+
| test.cpp:30:3:30:7 | call to chmod | Using arithmetic to compute the mask may not be safe. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
typedef int FILE;
2+
FILE *fopen(const char *filename, const char *mode);
3+
int umask(int pmode);
4+
int chmod(char * filename,int pmode);
5+
int fclose(FILE *stream);
6+
7+
void funcTest1()
8+
{
9+
umask(0666); // BAD
10+
FILE *fe;
11+
fe = fopen("myFile.txt", "wt");
12+
fclose(fe);
13+
chmod("myFile.txt",0666);
14+
}
15+
void funcTest1g()
16+
{
17+
umask(0022);
18+
FILE *fe;
19+
fe = fopen("myFile.txt", "wt");
20+
fclose(fe);
21+
chmod("myFile.txt",0666); // GOOD
22+
}
23+
24+
void funcTest2(int mode)
25+
{
26+
umask(mode);
27+
FILE *fe;
28+
fe = fopen("myFile.txt", "wt");
29+
fclose(fe);
30+
chmod("myFile.txt",0555-mode); // BAD
31+
}
32+
33+
void funcTest2g(int mode)
34+
{
35+
umask(mode);
36+
FILE *fe;
37+
fe = fopen("myFile.txt", "wt");
38+
fclose(fe);
39+
chmod("myFile.txt",0555&~mode); // GOOD
40+
}
41+
42+
int main(int argc, char *argv[])
43+
{
44+
funcTest1();
45+
funcTest2(27);
46+
funcTest1g();
47+
funcTest2g(27);
48+
return 0;
49+
}

0 commit comments

Comments
 (0)