@@ -911,25 +911,23 @@ private module Stdlib {
911
911
private string pathlibPathMethodExport ( ) { result in [ "as_posix" , "as_uri" ] }
912
912
913
913
/**
914
- * Flow for mehtods that return a `pathlib.Path` object.
914
+ * Flow for attributes and methods that return a `pathlib.Path` object.
915
915
*/
916
- private predicate typePreservingCall ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
917
- exists ( DataFlow:: AttrRead returnsPath | returnsPath .getAttributeName ( ) = pathlibPathMethod ( ) |
918
- nodeTo .( DataFlow:: CallCfgNode ) .getFunction ( ) = returnsPath and
916
+ private predicate pathlibPathStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
917
+ exists ( DataFlow:: AttrRead returnsPath |
918
+ (
919
+ // attribute access
920
+ returnsPath .getAttributeName ( ) = pathlibPathAttribute ( ) and
921
+ nodeTo = returnsPath
922
+ or
923
+ // method call
924
+ returnsPath .getAttributeName ( ) = pathlibPathMethod ( ) and
925
+ nodeTo .( DataFlow:: CallCfgNode ) .getFunction ( ) = returnsPath
926
+ ) and
919
927
nodeFrom = returnsPath .getObject ( )
920
928
)
921
929
}
922
930
923
- /**
924
- * Flow for attributes that are `pathlib.Path` objects.
925
- */
926
- private predicate typePreservingAttribute ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
927
- exists ( DataFlow:: AttrRead isPath | isPath .getAttributeName ( ) = pathlibPathAttribute ( ) |
928
- nodeTo = isPath and
929
- nodeFrom = isPath .getObject ( )
930
- )
931
- }
932
-
933
931
/**
934
932
* Gets a reference to a `pathlib.Path` object.
935
933
* This type tracker makes the monomorphic API use assumption.
@@ -939,22 +937,13 @@ private module Stdlib {
939
937
t .start ( ) and
940
938
result = pathlib ( ) .getMember ( pathlibPathConstructor ( ) ) .getACall ( )
941
939
or
942
- // Type-preserving call
940
+ // Type-preserving step
943
941
exists ( DataFlow:: Node nodeFrom , DataFlow:: TypeTracker t2 |
944
942
pathlibPath ( t2 ) .flowsTo ( nodeFrom ) and
945
943
t2 .end ( )
946
944
|
947
945
t .start ( ) and
948
- typePreservingCall ( nodeFrom , result )
949
- )
950
- or
951
- // Type-preserving attribute access
952
- exists ( DataFlow:: Node nodeFrom , DataFlow:: TypeTracker t2 |
953
- nodeFrom .getALocalSource ( ) = pathlibPath ( t2 ) and
954
- t2 .end ( )
955
- |
956
- t .start ( ) and
957
- typePreservingAttribute ( nodeFrom , result )
946
+ pathlibPathStep ( nodeFrom , result )
958
947
)
959
948
or
960
949
// Data injection
@@ -1013,14 +1002,7 @@ private module Stdlib {
1013
1002
or
1014
1003
// Type preservation
1015
1004
pathlibPath ( ) .flowsTo ( nodeFrom ) and
1016
- pathlibPath ( ) .flowsTo ( nodeTo ) and
1017
- (
1018
- // Type-preserving call
1019
- typePreservingCall ( nodeFrom , nodeTo )
1020
- or
1021
- // Type-preserving attribute access
1022
- typePreservingAttribute ( nodeFrom , nodeTo )
1023
- )
1005
+ pathlibPathStep ( nodeFrom , nodeTo )
1024
1006
or
1025
1007
// Data injection
1026
1008
pathlibPath ( ) .flowsTo ( nodeTo ) and
@@ -1053,20 +1035,16 @@ private module Stdlib {
1053
1035
or
1054
1036
// Export data from type
1055
1037
pathlibPath ( ) .flowsTo ( nodeFrom ) and
1056
- (
1038
+ exists ( DataFlow :: AttrRead exportPath |
1057
1039
// exporting attribute
1058
- exists ( DataFlow:: AttrRead export |
1059
- export .getAttributeName ( ) = pathlibPathAttributeExport ( )
1060
- |
1061
- nodeTo = export and
1062
- nodeFrom = export .getObject ( )
1063
- )
1040
+ exportPath .getAttributeName ( ) = pathlibPathAttributeExport ( ) and
1041
+ nodeTo = exportPath
1064
1042
or
1065
- // exporting call
1066
- exists ( DataFlow :: AttrRead export | export .getAttributeName ( ) = pathlibPathMethodExport ( ) |
1067
- nodeTo .( DataFlow:: CallCfgNode ) .getFunction ( ) = export and
1068
- nodeFrom = export . getObject ( )
1069
- )
1043
+ // exporting method
1044
+ exportPath .getAttributeName ( ) = pathlibPathMethodExport ( ) and
1045
+ nodeTo .( DataFlow:: CallCfgNode ) .getFunction ( ) = exportPath
1046
+ |
1047
+ nodeFrom = exportPath . getObject ( )
1070
1048
)
1071
1049
}
1072
1050
}
0 commit comments