Skip to content

Commit 440793b

Browse files
committed
C++: Move the example from the experimental CWE-089 query into a test.
1 parent 222cd41 commit 440793b

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-089/SqlTainted/SqlTainted.expected

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ edges
55
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
66
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 indirection |
77
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 indirection |
8+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | (const char *)... |
9+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | (const char *)... |
10+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | access to array |
11+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | access to array |
12+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | access to array |
13+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | access to array |
14+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | access to array indirection |
15+
| test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | access to array indirection |
816
nodes
917
| test.c:15:20:15:23 | argv | semmle.label | argv |
1018
| test.c:15:20:15:23 | argv | semmle.label | argv |
@@ -13,5 +21,15 @@ nodes
1321
| test.c:21:18:21:23 | query1 | semmle.label | query1 |
1422
| test.c:21:18:21:23 | query1 indirection | semmle.label | query1 indirection |
1523
| test.c:21:18:21:23 | query1 indirection | semmle.label | query1 indirection |
24+
| test.cpp:44:27:44:30 | argv | semmle.label | argv |
25+
| test.cpp:44:27:44:30 | argv | semmle.label | argv |
26+
| test.cpp:44:27:44:33 | (const char *)... | semmle.label | (const char *)... |
27+
| test.cpp:44:27:44:33 | (const char *)... | semmle.label | (const char *)... |
28+
| test.cpp:44:27:44:33 | access to array | semmle.label | access to array |
29+
| test.cpp:44:27:44:33 | access to array | semmle.label | access to array |
30+
| test.cpp:44:27:44:33 | access to array | semmle.label | access to array |
31+
| test.cpp:44:27:44:33 | access to array indirection | semmle.label | access to array indirection |
32+
| test.cpp:44:27:44:33 | access to array indirection | semmle.label | access to array indirection |
1633
#select
1734
| test.c:21:18:21:23 | query1 | test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg) | test.c:15:20:15:23 | argv | user input (argv) |
35+
| test.cpp:44:27:44:33 | access to array | test.cpp:44:27:44:30 | argv | test.cpp:44:27:44:33 | access to array | This argument to a SQL query function is derived from $@ and then passed to pqxx::work::exec1((unnamed parameter 0)) | test.cpp:44:27:44:30 | argv | user input (argv) |
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
int sprintf(char* str, const char* format, ...);
2+
3+
namespace std
4+
{
5+
template<class charT> struct char_traits;
6+
7+
template <class T> class allocator {
8+
public:
9+
allocator() throw();
10+
};
11+
12+
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
13+
class basic_string {
14+
public:
15+
explicit basic_string(const Allocator& a = Allocator());
16+
basic_string(const charT* s, const Allocator& a = Allocator());
17+
18+
const charT* c_str() const;
19+
};
20+
21+
typedef basic_string<char> string;
22+
}
23+
24+
namespace pqxx {
25+
struct connection {};
26+
27+
struct row {};
28+
struct result {};
29+
30+
struct work {
31+
work(connection&);
32+
33+
row exec1(const char*);
34+
result exec(const std::string&);
35+
std::string quote(const char*);
36+
};
37+
}
38+
39+
int main(int argc, char** argv) {
40+
pqxx::connection c;
41+
pqxx::work w(c);
42+
43+
pqxx::row r = w.exec1(argv[1]); // BAD
44+
45+
pqxx::result r2 = w.exec(w.quote(argv[1])); // GOOD
46+
47+
return 0;
48+
}

0 commit comments

Comments
 (0)