Skip to content

Commit 47faf5f

Browse files
keshavdvfacebook-github-bot
authored andcommitted
Improve name extraction for non-python methods
Summary: For slot wrappers like the ones that thrift generates, the existing qualified name generation does not correctly identify the parent module, leading to failures in pysa. Reviewed By: gbleaney Differential Revision: D30091530 fbshipit-source-id: 689250a737b25291e2d6ff9fceb73fe04eb364b5
1 parent 76a4fbe commit 47faf5f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tools/generate_taint_models/inspect_parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def extract_qualified_name(callable_object: Callable[..., object]) -> Optional[s
2020
return extract_qualified_name(callable_object.__func__)
2121
else:
2222
module_name = getattr(callable_object, "__module__", None)
23+
# Try and fallback to objclass
24+
if module_name is None and (
25+
objclass := getattr(callable_object, "__objclass__", None)
26+
):
27+
module_name = getattr(objclass, "__module__", None)
2328
view_name = getattr(
2429
callable_object, "__qualname__", callable_object.__class__.__qualname__
2530
)

tools/generate_taint_models/tests/inspect_parser_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import unittest
77

8+
from testing.types import File
9+
810
from ..inspect_parser import extract_parameters, extract_qualified_name
911
from ..parameter import Parameter
1012

@@ -65,3 +67,9 @@ def test_extract_parameters(self) -> None:
6567
self.assertEqual(
6668
extract_parameters(TestMethodClass.test_method), expected_parameters
6769
)
70+
71+
def test_thrift_structs(self) -> None:
72+
self.assertEqual(
73+
extract_qualified_name(File.__hash__),
74+
"testing.types.File.__hash__",
75+
)

0 commit comments

Comments
 (0)