Skip to content

Commit ff788c9

Browse files
committed
C++: Add a model for 'std::format' and a failing test.
1 parent c989e01 commit ff788c9

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

cpp/ql/test/library-tests/dataflow/taint-tests/format.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include "stl.h"
22
typedef unsigned long size_t;
33
typedef struct {} FILE;
44

@@ -157,3 +157,8 @@ void test2()
157157
sink(s[strlen(s) - 1]); // $ ast,ir
158158
sink(ws + (wcslen(ws) / 2)); // $ ast,ir
159159
}
160+
161+
void test_format() {
162+
auto s = std::format("{}", string::source());
163+
sink(s); // $ MISSING: ast,ir
164+
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
447447
| format.cpp:158:13:158:18 | call to wcslen | format.cpp:158:13:158:26 | ... / ... | TAINT |
448448
| format.cpp:158:13:158:26 | ... / ... | format.cpp:158:7:158:27 | ... + ... | TAINT |
449449
| format.cpp:158:26:158:26 | 2 | format.cpp:158:13:158:26 | ... / ... | TAINT |
450+
| format.cpp:162:12:162:22 | call to format | format.cpp:163:8:163:8 | s | |
451+
| format.cpp:162:24:162:27 | {} | format.cpp:162:24:162:27 | call to basic_format_string | TAINT |
450452
| map.cpp:21:28:21:28 | call to pair | map.cpp:23:2:23:2 | a | |
451453
| map.cpp:21:28:21:28 | call to pair | map.cpp:24:7:24:7 | a | |
452454
| map.cpp:21:28:21:28 | call to pair | map.cpp:25:7:25:7 | a | |

cpp/ql/test/library-tests/dataflow/taint-tests/stl.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,38 @@ namespace std {
642642
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
643643
};
644644
}
645+
646+
// --- string view ---
647+
648+
namespace std {
649+
template<class CharT, class Traits = char_traits<CharT>>
650+
class basic_string_view {
651+
public:
652+
using size_type = size_t;
653+
654+
basic_string_view() noexcept;
655+
basic_string_view(const basic_string_view&) noexcept;
656+
basic_string_view(const CharT*, size_type);
657+
basic_string_view(const CharT*);
658+
template<class It, class End> basic_string_view(It, End);
659+
template<class R> explicit basic_string_view(R&&);
660+
basic_string_view& operator=(const basic_string_view&) noexcept;
661+
};
662+
663+
using string_view = basic_string_view<char>;
664+
}
665+
666+
// --- format ---
667+
namespace std {
668+
template<class CharT /* class... Args */>
669+
struct basic_format_string {
670+
public:
671+
template<class T> basic_format_string(const T&);
672+
673+
basic_string_view<CharT> get() const noexcept;
674+
};
675+
676+
using format_string = basic_format_string<char>; // simplified from `char, std::type_identity_t<Args>...`
677+
678+
template<class... Args> string format( format_string fmt, Args&&... args );
679+
}

cpp/ql/test/library-tests/dataflow/taint-tests/test_mad-signatures.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,4 @@ getParameterTypeName
650650
| stl.h:636:37:636:41 | merge | 0 | unordered_set & |
651651
| stl.h:639:12:639:15 | find | 0 | const key_type & |
652652
| stl.h:641:28:641:38 | equal_range | 0 | const key_type & |
653+
| stl.h:671:21:671:39 | basic_format_string | 0 | const func:0 & |

0 commit comments

Comments
 (0)