File tree 1 file changed +23
-3
lines changed
cpp/ql/src/Security/CWE/CWE-732
1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 1
1
void write_default_config_bad () {
2
2
// BAD - this is world-writable so any user can overwrite the config
3
3
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 );
5
10
}
6
11
7
12
void write_default_config_good () {
8
13
// GOOD - this allows only the current user to modify the file
9
14
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 );
11
21
}
12
22
13
23
void write_default_config_good_2 () {
14
24
// GOOD - this allows only the current user to modify the file
15
25
int out = open (OUTFILE , O_WRONLY | O_CREAT , S_IWUSR | S_IRUSR );
26
+ if (out < 0 ) {
27
+ // handle error
28
+ }
29
+
16
30
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 );
18
38
}
You can’t perform that action at this time.
0 commit comments