File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
cpp/ql/src/Security/CWE/CWE-732 Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 11void write_default_config_bad () {
22 // BAD - this is world-writable so any user can overwrite the config
33 int out = creat (OUTFILE , 0666 );
4- dprintf (out , DEFAULT_CONFIG );
4+ if (out < 0 ) {
5+ // handle error
6+ }
7+
8+ dprintf (out , "%s" , DEFAULT_CONFIG );
9+ close (out );
510}
611
712void write_default_config_good () {
813 // GOOD - this allows only the current user to modify the file
914 int out = creat (OUTFILE , S_IWUSR | S_IRUSR );
10- dprintf (out , DEFAULT_CONFIG );
15+ if (out < 0 ) {
16+ // handle error
17+ }
18+
19+ dprintf (out , "%s" , DEFAULT_CONFIG );
20+ close (out );
1121}
1222
1323void write_default_config_good_2 () {
1424 // GOOD - this allows only the current user to modify the file
1525 int out = open (OUTFILE , O_WRONLY | O_CREAT , S_IWUSR | S_IRUSR );
26+ if (out < 0 ) {
27+ // handle error
28+ }
29+
1630 FILE * fd = fdopen (out , "w" );
17- fprintf (fd , DEFAULT_CONFIG );
31+ if (fd == NULL ) {
32+ close (out );
33+ // handle error
34+ }
35+
36+ fprintf (fd , "%s" , DEFAULT_CONFIG );
37+ fclose (fd );
1838}
You can’t perform that action at this time.
0 commit comments