12
12
*/
13
13
14
14
import python
15
+ import semmle.python.ApiGraphs
15
16
16
17
bindingset [ p]
17
18
int world_permission ( int p ) { result = p % 8 }
@@ -33,20 +34,20 @@ string permissive_permission(int p) {
33
34
world_permission ( p ) = 0 and result = "group " + access ( group_permission ( p ) )
34
35
}
35
36
36
- predicate chmod_call ( CallNode call , FunctionValue chmod , NumericValue num ) {
37
- Value :: named ( "os. chmod" ) = chmod and
38
- chmod . getACall ( ) = call and
39
- call . getArg ( 1 ) . pointsTo ( num )
37
+ predicate chmod_call ( API :: CallNode call , string name , int mode ) {
38
+ call = API :: moduleImport ( "os" ) . getMember ( " chmod") . getACall ( ) and
39
+ mode = call . getParameter ( 1 , "mode" ) . getAValueReachingRhs ( ) . asExpr ( ) . ( IntegerLiteral ) . getValue ( ) and
40
+ name = "chmod"
40
41
}
41
42
42
- predicate open_call ( CallNode call , FunctionValue open , NumericValue num ) {
43
- Value :: named ( "os. open" ) = open and
44
- open . getACall ( ) = call and
45
- call . getArg ( 2 ) . pointsTo ( num )
43
+ predicate open_call ( API :: CallNode call , string name , int mode ) {
44
+ call = API :: moduleImport ( "os" ) . getMember ( " open") . getACall ( ) and
45
+ mode = call . getParameter ( 2 , "mode" ) . getAValueReachingRhs ( ) . asExpr ( ) . ( IntegerLiteral ) . getValue ( ) and
46
+ name = "open"
46
47
}
47
48
48
- from CallNode call , FunctionValue func , NumericValue num , string permission
49
+ from API :: CallNode call , string name , int mode , string permission
49
50
where
50
- ( chmod_call ( call , func , num ) or open_call ( call , func , num ) ) and
51
- permission = permissive_permission ( num . getIntValue ( ) )
52
- select call , "Overly permissive mask in " + func . getName ( ) + " sets file to " + permission + "."
51
+ ( chmod_call ( call , name , mode ) or open_call ( call , name , mode ) ) and
52
+ permission = permissive_permission ( mode )
53
+ select call , "Overly permissive mask in " + name + " sets file to " + permission + "."
0 commit comments