@@ -399,13 +399,55 @@ module RustDataFlow implements InputSig<Location> {
399
399
400
400
final class ReturnKind = ReturnKindAlias ;
401
401
402
+ private import codeql.util.Option
403
+
404
+ private class CrateOrigin extends string {
405
+ CrateOrigin ( ) {
406
+ this = [ any ( Item i ) .getCrateOrigin ( ) , any ( Resolvable r ) .getResolvedCrateOrigin ( ) ]
407
+ }
408
+ }
409
+
410
+ private class CrateOriginOption = Option< CrateOrigin > :: Option ;
411
+
412
+ pragma [ nomagic]
413
+ private predicate hasExtendedCanonicalPath (
414
+ DataFlowCallable c , CrateOriginOption crate , string path
415
+ ) {
416
+ exists ( Item i |
417
+ i = c .asCfgScope ( ) and
418
+ path = i .getExtendedCanonicalPath ( )
419
+ |
420
+ crate .asSome ( ) = i .getCrateOrigin ( )
421
+ or
422
+ crate .isNone ( ) and
423
+ not i .hasCrateOrigin ( )
424
+ )
425
+ }
426
+
427
+ pragma [ nomagic]
428
+ private predicate resolvesExtendedCanonicalPath (
429
+ DataFlowCall c , CrateOriginOption crate , string path
430
+ ) {
431
+ exists ( Resolvable r |
432
+ path = r .getResolvedPath ( ) and
433
+ (
434
+ r = c .asMethodCallExprCfgNode ( ) .getExpr ( )
435
+ or
436
+ r = c .asCallExprCfgNode ( ) .getExpr ( ) .( PathExprCfgNode ) .getPath ( )
437
+ )
438
+ |
439
+ crate .asSome ( ) = r .getResolvedCrateOrigin ( )
440
+ or
441
+ crate .isNone ( ) and
442
+ not r .hasResolvedCrateOrigin ( )
443
+ )
444
+ }
445
+
402
446
/** Gets a viable implementation of the target of the given `Call`. */
403
- DataFlowCallable viableCallable ( DataFlowCall c ) {
404
- exists ( Function f , string name | result .asCfgScope ( ) = f and name = f .getName ( ) .toString ( ) |
405
- if f .getParamList ( ) .hasSelfParam ( )
406
- then name = c .asMethodCallExprCfgNode ( ) .getNameRef ( ) .getText ( )
407
- else
408
- name = c .asCallExprCfgNode ( ) .getExpr ( ) .getExpr ( ) .( PathExpr ) .getPath ( ) .getPart ( ) .toString ( )
447
+ DataFlowCallable viableCallable ( DataFlowCall call ) {
448
+ exists ( string path , CrateOriginOption crate |
449
+ hasExtendedCanonicalPath ( result , crate , path ) and
450
+ resolvesExtendedCanonicalPath ( call , crate , path )
409
451
)
410
452
}
411
453
0 commit comments