Skip to content

Commit b800040

Browse files
committed
C++: Add tests for various local Windows dataflow sources
1 parent 0822ded commit b800040

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

cpp/ql/test/library-tests/dataflow/dataflow-tests/TestBase.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ module IRTest {
124124

125125
/** Common data flow configuration to be used by tests. */
126126
module IRTestAllocationConfig implements DataFlow::ConfigSig {
127+
private import semmle.code.cpp.security.FlowSources
128+
127129
predicate isSource(DataFlow::Node source) {
130+
source instanceof FlowSource
131+
or
128132
source.asExpr().(FunctionCall).getTarget().getName() = "source"
129133
or
130134
source.asIndirectExpr(1).(FunctionCall).getTarget().getName() = "indirect_source"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void sink(char);
2+
void sink(char*);
3+
4+
int WinMain(void *hInstance, void *hPrevInstance, char *pCmdLine, int nCmdShow) { // $ ast-def=hInstance ast-def=hPrevInstance ast-def=pCmdLine ir-def=*hInstance ir-def=*hPrevInstance ir-def=*pCmdLine
5+
sink(pCmdLine);
6+
sink(*pCmdLine); // $ MISSING: ir
7+
8+
return 0;
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
void sink(char);
2+
void sink(char*);
3+
void sink(char**);
4+
5+
char* GetCommandLineA();
6+
char** CommandLineToArgvA(char*, int*);
7+
char* GetEnvironmentStringsA();
8+
int GetEnvironmentVariableA(const char*, char*, int);
9+
10+
void getCommandLine() {
11+
char* cmd = GetCommandLineA();
12+
sink(cmd);
13+
sink(*cmd); // $ MISSING: ir
14+
15+
int argc;
16+
char** argv = CommandLineToArgvA(cmd, &argc);
17+
sink(argv);
18+
sink(argv[1]);
19+
sink(*argv[1]); // $ MISSING: ir
20+
}
21+
22+
void getEnvironment() {
23+
char* env = GetEnvironmentStringsA();
24+
sink(env);
25+
sink(*env); // $ MISSING: ir
26+
27+
char buf[1024];
28+
GetEnvironmentVariableA("FOO", buf, sizeof(buf));
29+
sink(buf);
30+
sink(*buf); // $ MISSING: ir
31+
}

0 commit comments

Comments
 (0)