1212 */
1313
1414import python
15+ import semmle.python.ApiGraphs
1516
1617bindingset [ p]
1718int world_permission ( int p ) { result = p % 8 }
@@ -33,20 +34,20 @@ string permissive_permission(int p) {
3334 world_permission ( p ) = 0 and result = "group " + access ( group_permission ( p ) )
3435}
3536
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"
4041}
4142
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"
4647}
4748
48- from CallNode call , FunctionValue func , NumericValue num , string permission
49+ from API :: CallNode call , string name , int mode , string permission
4950where
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