@@ -4,9 +4,18 @@ import go
4
4
5
5
/** Provides models of commonly used functions and types in the protobuf packages. */
6
6
module Protobuf {
7
- /** Gets the name of a protobuf implementation package. */
7
+ /** Gets the name of the modern protobuf top-level implementation package. */
8
+ string modernProtobufPackage ( ) { result = "google.golang.org/protobuf/proto" }
9
+
10
+ /** Gets the name of the modern protobuf implementation's `protoiface` subpackage. */
11
+ string protobufIfacePackage ( ) { result = "google.golang.org/protobuf/runtime/protoiface" }
12
+
13
+ /** Gets the name of the modern protobuf implementation's `protoreflect` subpackage. */
14
+ string protobufReflectPackage ( ) { result = "google.golang.org/protobuf/reflect/protoreflect" }
15
+
16
+ /** Gets the name of a top-level protobuf implementation package. */
8
17
string protobufPackages ( ) {
9
- result in [ "github.com/golang/protobuf/proto" , "google.golang.org/protobuf/proto" ]
18
+ result in [ "github.com/golang/protobuf/proto" , modernProtobufPackage ( ) ]
10
19
}
11
20
12
21
/** The `Marshal` and `MarshalAppend` functions in the protobuf packages. */
@@ -17,7 +26,7 @@ module Protobuf {
17
26
name = [ "Marshal" , "MarshalAppend" ] and
18
27
(
19
28
this .hasQualifiedName ( protobufPackages ( ) , name ) or
20
- this .( Method ) .hasQualifiedName ( "google.golang.org/protobuf/proto" , "MarshalOptions" , name )
29
+ this .( Method ) .hasQualifiedName ( modernProtobufPackage ( ) , "MarshalOptions" , name )
21
30
)
22
31
}
23
32
@@ -39,14 +48,11 @@ module Protobuf {
39
48
}
40
49
41
50
private Field inputMessageField ( ) {
42
- result
43
- .hasQualifiedName ( "google.golang.org/protobuf/runtime/protoiface" , "MarshalInput" , "Message" )
51
+ result .hasQualifiedName ( protobufIfacePackage ( ) , "MarshalInput" , "Message" )
44
52
}
45
53
46
54
private Method marshalStateMethod ( ) {
47
- result
48
- .hasQualifiedName ( "google.golang.org/protobuf/runtime/protoiface" , "MarshalOptions" ,
49
- "MarshalState" )
55
+ result .hasQualifiedName ( protobufIfacePackage ( ) , "MarshalOptions" , "MarshalState" )
50
56
}
51
57
52
58
/**
@@ -76,9 +82,7 @@ module Protobuf {
76
82
class UnmarshalFunction extends TaintTracking:: FunctionModel , UnmarshalingFunction:: Range {
77
83
UnmarshalFunction ( ) {
78
84
this .hasQualifiedName ( protobufPackages ( ) , "Unmarshal" ) or
79
- this
80
- .( Method )
81
- .hasQualifiedName ( "google.golang.org/protobuf/proto" , "UnmarshalOptions" , "Unmarshal" )
85
+ this .( Method ) .hasQualifiedName ( modernProtobufPackage ( ) , "UnmarshalOptions" , "Unmarshal" )
82
86
}
83
87
84
88
override predicate hasTaintFlow ( DataFlow:: FunctionInput inp , DataFlow:: FunctionOutput outp ) {
@@ -103,9 +107,7 @@ module Protobuf {
103
107
104
108
/** A protobuf `Message` type. */
105
109
class MessageType extends Type {
106
- MessageType ( ) {
107
- this .implements ( "google.golang.org/protobuf/reflect/protoreflect" , "ProtoMessage" )
108
- }
110
+ MessageType ( ) { this .implements ( protobufReflectPackage ( ) , "ProtoMessage" ) }
109
111
}
110
112
111
113
/** The `Clone` function in the protobuf packages. */
0 commit comments