Skip to content

Commit 61bdd3c

Browse files
authored
Merge pull request #22524 from MathiasVP/model-boost-asio-resolve
C++: Add taint models for `boost::asio::ip::resolve`
2 parents de9aa42 + ae6fb33 commit 61bdd3c

9 files changed

Lines changed: 432 additions & 26 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added taint flow models for the `boost::asio::ip::basic_resolver::resolve` function.

cpp/ql/lib/ext/Boost.Asio.model.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,19 @@ extensions:
2323
extensible: summaryModel
2424
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
2525
- ["boost::asio", "", False, "buffer", "", "", "Argument[*0]", "ReturnValue", "taint", "manual"]
26+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const string &,const string &)", "", "Argument[*0..1]", "ReturnValue", "taint", "manual"]
27+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const string &,const string &,error_code &)", "", "Argument[*0..1]", "ReturnValue", "taint", "manual"]
28+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const string &,const string &,flags)", "", "Argument[*0..1]", "ReturnValue", "taint", "manual"]
29+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const string &,const string &,flags,error_code &)", "", "Argument[*0..1]", "ReturnValue", "taint", "manual"]
30+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(string_view,string_view)", "", "Argument[0..1]", "ReturnValue", "taint", "manual"]
31+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(string_view,string_view,error_code &)", "", "Argument[0..1]", "ReturnValue", "taint", "manual"]
32+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(string_view,string_view,flags)", "", "Argument[0..1]", "ReturnValue", "taint", "manual"]
33+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(string_view,string_view,flags,error_code &)", "", "Argument[0..1]", "ReturnValue", "taint", "manual"]
34+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,const string &,const string &)", "", "Argument[*1..2]", "ReturnValue", "taint", "manual"]
35+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,const string &,const string &,error_code &)", "", "Argument[*1..2]", "ReturnValue", "taint", "manual"]
36+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,const string &,const string &,flags)", "", "Argument[*1..2]", "ReturnValue", "taint", "manual"]
37+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,const string &,const string &,flags,error_code &)", "", "Argument[*1..2]", "ReturnValue", "taint", "manual"]
38+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,string_view,string_view)", "", "Argument[1..2]", "ReturnValue", "taint", "manual"]
39+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,string_view,string_view,error_code &)", "", "Argument[1..2]", "ReturnValue", "taint", "manual"]
40+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,string_view,string_view,flags)", "", "Argument[1..2]", "ReturnValue", "taint", "manual"]
41+
- ["boost::asio::ip", "basic_resolver<InternetProtocol>", False, "resolve", "(const InternetProtocol &,string_view,string_view,flags,error_code &)", "", "Argument[1..2]", "ReturnValue", "taint", "manual"]

cpp/ql/test/library-tests/dataflow/external-models/asio_streams.cpp

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace std {
1818
};
1919

2020
typedef basic_string<char> string;
21+
22+
class string_view {
23+
public:
24+
string_view(const char* s);
25+
};
2126
};
2227

2328
namespace boost {
@@ -29,14 +34,50 @@ namespace boost {
2934
};
3035

3136
namespace asio {
32-
template<typename Protocol/*, typename Executor*/>
33-
class basic_stream_socket /*: public basic_socket<Protocol, Executor>*/ {
34-
};
37+
class any_io_executor { };
38+
39+
class socket_base { };
40+
41+
template <typename Protocol, typename Executor>
42+
class basic_socket : public socket_base { };
43+
44+
template<typename Protocol, typename Executor = any_io_executor>
45+
class basic_stream_socket : public basic_socket<Protocol, Executor> { };
3546

3647
namespace ip {
48+
class resolver_base {
49+
public:
50+
enum flags { passive = 1 };
51+
};
52+
53+
template<typename InternetProtocol, typename Executor = any_io_executor>
54+
class basic_resolver {
55+
public:
56+
class results_type {
57+
};
58+
59+
results_type resolve(const std::string &host, const std::string &service);
60+
results_type resolve(const std::string &host, const std::string &service, boost::system::error_code &ec);
61+
results_type resolve(const std::string &host, const std::string &service, resolver_base::flags resolve_flags);
62+
results_type resolve(const std::string &host, const std::string &service, resolver_base::flags resolve_flags, boost::system::error_code &ec);
63+
results_type resolve(std::string_view host, std::string_view service);
64+
results_type resolve(std::string_view host, std::string_view service, boost::system::error_code &ec);
65+
results_type resolve(std::string_view host, std::string_view service, resolver_base::flags resolve_flags);
66+
results_type resolve(std::string_view host, std::string_view service, resolver_base::flags resolve_flags, boost::system::error_code &ec);
67+
results_type resolve(const InternetProtocol &protocol, const std::string &host, const std::string &service);
68+
results_type resolve(const InternetProtocol &protocol, const std::string &host, const std::string &service, boost::system::error_code &ec);
69+
results_type resolve(const InternetProtocol &protocol, const std::string &host, const std::string &service, resolver_base::flags resolve_flags);
70+
results_type resolve(const InternetProtocol &protocol, const std::string &host, const std::string &service, resolver_base::flags resolve_flags, boost::system::error_code &ec);
71+
results_type resolve(const InternetProtocol &protocol, std::string_view host, std::string_view service);
72+
results_type resolve(const InternetProtocol &protocol, std::string_view host, std::string_view service, boost::system::error_code &ec);
73+
results_type resolve(const InternetProtocol &protocol, std::string_view host, std::string_view service, resolver_base::flags resolve_flags);
74+
results_type resolve(const InternetProtocol &protocol, std::string_view host, std::string_view service, resolver_base::flags resolve_flags, boost::system::error_code &ec);
75+
};
76+
3777
class tcp {
3878
public:
3979
typedef basic_stream_socket<tcp> socket;
80+
typedef basic_resolver<tcp> resolver;
4081
};
4182
};
4283

@@ -76,6 +117,7 @@ void sink(char *);
76117
void sink(std::string);
77118
void sink(boost::asio::streambuf);
78119
void sink(boost::asio::mutable_buffer);
120+
void sink(boost::asio::ip::tcp::resolver::results_type);
79121

80122
char *getenv(const char *name);
81123
int send(int, const void*, int, int);
@@ -105,3 +147,65 @@ void test(boost::asio::ip::tcp::socket &socket) {
105147
// ...
106148
}
107149
}
150+
151+
void test_resolve_host() {
152+
boost::asio::ip::tcp::resolver resolver;
153+
boost::asio::ip::tcp protocol;
154+
boost::asio::ip::resolver_base::flags flags = boost::asio::ip::resolver_base::passive;
155+
boost::system::error_code error;
156+
std::string host(source());
157+
std::string service("");
158+
std::string_view host_view(source());
159+
std::string_view service_view("");
160+
161+
sink(resolver.resolve(host, service)); // $ ir
162+
sink(resolver.resolve(host, service, error)); // $ ir
163+
sink(resolver.resolve(host, service, flags)); // $ ir
164+
sink(resolver.resolve(host, service, flags, error)); // $ ir
165+
166+
sink(resolver.resolve(host_view, service_view)); // $ ir
167+
sink(resolver.resolve(host_view, service_view, error)); // $ ir
168+
sink(resolver.resolve(host_view, service_view, flags)); // $ ir
169+
sink(resolver.resolve(host_view, service_view, flags, error)); // $ ir
170+
171+
sink(resolver.resolve(protocol, host, service)); // $ ir
172+
sink(resolver.resolve(protocol, host, service, error)); // $ ir
173+
sink(resolver.resolve(protocol, host, service, flags)); // $ ir
174+
sink(resolver.resolve(protocol, host, service, flags, error)); // $ ir
175+
176+
sink(resolver.resolve(protocol, host_view, service_view)); // $ ir
177+
sink(resolver.resolve(protocol, host_view, service_view, error)); // $ ir
178+
sink(resolver.resolve(protocol, host_view, service_view, flags)); // $ ir
179+
sink(resolver.resolve(protocol, host_view, service_view, flags, error)); // $ ir
180+
}
181+
182+
void test_resolve_service() {
183+
boost::asio::ip::tcp::resolver resolver;
184+
boost::asio::ip::tcp protocol;
185+
boost::asio::ip::resolver_base::flags flags = boost::asio::ip::resolver_base::passive;
186+
boost::system::error_code error;
187+
std::string host("");
188+
std::string service(source());
189+
std::string_view host_view("");
190+
std::string_view service_view(source());
191+
192+
sink(resolver.resolve(host, service)); // $ ir
193+
sink(resolver.resolve(host, service, error)); // $ ir
194+
sink(resolver.resolve(host, service, flags)); // $ ir
195+
sink(resolver.resolve(host, service, flags, error)); // $ ir
196+
197+
sink(resolver.resolve(host_view, service_view)); // $ ir
198+
sink(resolver.resolve(host_view, service_view, error)); // $ ir
199+
sink(resolver.resolve(host_view, service_view, flags)); // $ ir
200+
sink(resolver.resolve(host_view, service_view, flags, error)); // $ ir
201+
202+
sink(resolver.resolve(protocol, host, service)); // $ ir
203+
sink(resolver.resolve(protocol, host, service, error)); // $ ir
204+
sink(resolver.resolve(protocol, host, service, flags)); // $ ir
205+
sink(resolver.resolve(protocol, host, service, flags, error)); // $ ir
206+
207+
sink(resolver.resolve(protocol, host_view, service_view)); // $ ir
208+
sink(resolver.resolve(protocol, host_view, service_view, error)); // $ ir
209+
sink(resolver.resolve(protocol, host_view, service_view, flags)); // $ ir
210+
sink(resolver.resolve(protocol, host_view, service_view, flags, error)); // $ ir
211+
}

0 commit comments

Comments
 (0)