Skip to content

Commit c36e918

Browse files
committed
C++: Fix a test case.
1 parent 0ca9b22 commit c36e918

File tree

1 file changed

+7
-7
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-078/semmle/ExecTainted

1 file changed

+7
-7
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-078/semmle/ExecTainted/test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern void encodeShellString(char *shellStr, int maxChars, const char* cStr);
1414

1515
int main(int argc, char** argv) {
1616
char *userName = argv[2];
17-
17+
1818
{
1919
// BAD: a string from the user is injected directly into
2020
// a command.
@@ -23,10 +23,10 @@ int main(int argc, char** argv) {
2323
system(command1);
2424
}
2525

26-
{
26+
{
2727
// GOOD: the user string is encoded by a library routine.
2828
char userNameQuoted[1000] = {0};
29-
encodeShellString(userNameQuoted, 1000, userName);
29+
encodeShellString(userNameQuoted, 1000, userName);
3030
char command2[1000] = {0};
3131
sprintf(command2, "userinfo -v %s", userNameQuoted);
3232
system(command2);
@@ -36,16 +36,16 @@ int main(int argc, char** argv) {
3636
void test2(char* arg2) {
3737
// GOOD?: the user string is the *first* part of the command, like $CC in many environments
3838
char *envCC = getenv("CC");
39-
39+
4040
char command[1000];
41-
sprintf("%s %s", envCC, arg2);
41+
sprintf(command, "%s %s", envCC, arg2);
4242
system(command);
4343
}
4444

4545
void test3(char* arg1) {
4646
// GOOD?: the user string is a `$CFLAGS` environment variable
4747
char *envCflags = getenv("CFLAGS");
48-
48+
4949
char command[1000];
5050
sprintf(command, "%s %s", arg1, envCflags);
5151
system(command);
@@ -160,7 +160,7 @@ void test15(FILE *f) {
160160
fread(temp, 1, 10, f);
161161

162162
int x = atoi(temp);
163-
163+
164164
char temp2[10];
165165
sprintf(temp2, "%d", x);
166166
sprintf(command, "tail -n %s foo.log", temp2);

0 commit comments

Comments
 (0)