File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
cpp/ql/test/experimental/query-tests/Security/CWE/CWE-266/semmle/tests Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 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 number Diff line number Diff line change 1+ experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments