11import semmle.code.cpp.models.interfaces.Taint
22import semmle.code.cpp.models.interfaces.Alias
33import semmle.code.cpp.models.interfaces.ArrayFunction
4+ import semmle.code.cpp.models.interfaces.FlowSource
45
56private class InetNtoa extends TaintFunction {
6- InetNtoa ( ) { hasGlobalName ( "inet_ntoa" ) }
7+ InetNtoa ( ) { this . hasGlobalName ( "inet_ntoa" ) }
78
89 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
910 input .isParameter ( 0 ) and
@@ -12,7 +13,7 @@ private class InetNtoa extends TaintFunction {
1213}
1314
1415private class InetAton extends TaintFunction , ArrayFunction {
15- InetAton ( ) { hasGlobalName ( "inet_aton" ) }
16+ InetAton ( ) { this . hasGlobalName ( "inet_aton" ) }
1617
1718 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
1819 input .isParameterDeref ( 0 ) and
@@ -32,7 +33,7 @@ private class InetAton extends TaintFunction, ArrayFunction {
3233}
3334
3435private class InetAddr extends TaintFunction , ArrayFunction , AliasFunction {
35- InetAddr ( ) { hasGlobalName ( "inet_addr" ) }
36+ InetAddr ( ) { this . hasGlobalName ( "inet_addr" ) }
3637
3738 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
3839 input .isParameterDeref ( 0 ) and
@@ -51,7 +52,7 @@ private class InetAddr extends TaintFunction, ArrayFunction, AliasFunction {
5152}
5253
5354private class InetNetwork extends TaintFunction , ArrayFunction {
54- InetNetwork ( ) { hasGlobalName ( "inet_network" ) }
55+ InetNetwork ( ) { this . hasGlobalName ( "inet_network" ) }
5556
5657 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
5758 input .isParameterDeref ( 0 ) and
@@ -64,7 +65,7 @@ private class InetNetwork extends TaintFunction, ArrayFunction {
6465}
6566
6667private class InetMakeaddr extends TaintFunction {
67- InetMakeaddr ( ) { hasGlobalName ( "inet_makeaddr" ) }
68+ InetMakeaddr ( ) { this . hasGlobalName ( "inet_makeaddr" ) }
6869
6970 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
7071 (
@@ -76,7 +77,7 @@ private class InetMakeaddr extends TaintFunction {
7677}
7778
7879private class InetLnaof extends TaintFunction {
79- InetLnaof ( ) { hasGlobalName ( "inet_lnaof" ) }
80+ InetLnaof ( ) { this . hasGlobalName ( "inet_lnaof" ) }
8081
8182 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
8283 input .isParameter ( 0 ) and
@@ -85,7 +86,7 @@ private class InetLnaof extends TaintFunction {
8586}
8687
8788private class InetNetof extends TaintFunction {
88- InetNetof ( ) { hasGlobalName ( "inet_netof" ) }
89+ InetNetof ( ) { this . hasGlobalName ( "inet_netof" ) }
8990
9091 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
9192 input .isParameter ( 0 ) and
@@ -94,7 +95,7 @@ private class InetNetof extends TaintFunction {
9495}
9596
9697private class InetPton extends TaintFunction , ArrayFunction {
97- InetPton ( ) { hasGlobalName ( "inet_pton" ) }
98+ InetPton ( ) { this . hasGlobalName ( "inet_pton" ) }
9899
99100 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
100101 (
@@ -114,7 +115,7 @@ private class InetPton extends TaintFunction, ArrayFunction {
114115}
115116
116117private class Gethostbyname extends TaintFunction , ArrayFunction {
117- Gethostbyname ( ) { hasGlobalName ( "gethostbyname" ) }
118+ Gethostbyname ( ) { this . hasGlobalName ( "gethostbyname" ) }
118119
119120 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
120121 input .isParameterDeref ( 0 ) and
@@ -127,7 +128,7 @@ private class Gethostbyname extends TaintFunction, ArrayFunction {
127128}
128129
129130private class Gethostbyaddr extends TaintFunction , ArrayFunction {
130- Gethostbyaddr ( ) { hasGlobalName ( "gethostbyaddr" ) }
131+ Gethostbyaddr ( ) { this . hasGlobalName ( "gethostbyaddr" ) }
131132
132133 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
133134 (
@@ -142,3 +143,21 @@ private class Gethostbyaddr extends TaintFunction, ArrayFunction {
142143
143144 override predicate hasArrayWithNullTerminator ( int bufParam ) { bufParam = 0 }
144145}
146+
147+ private class Getaddrinfo extends TaintFunction , ArrayFunction , RemoteFlowSourceFunction {
148+ Getaddrinfo ( ) { this .hasGlobalName ( "getaddrinfo" ) }
149+
150+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
151+ input .isParameterDeref ( [ 0 .. 2 ] ) and
152+ output .isParameterDeref ( 3 )
153+ }
154+
155+ override predicate hasArrayInput ( int bufParam ) { bufParam in [ 0 , 1 ] }
156+
157+ override predicate hasArrayWithNullTerminator ( int bufParam ) { bufParam in [ 0 , 1 ] }
158+
159+ override predicate hasRemoteFlowSource ( FunctionOutput output , string description ) {
160+ output .isParameterDeref ( 3 ) and
161+ description = "Address returned by " + this .getName ( )
162+ }
163+ }
0 commit comments