Skip to content

Commit dda52a2

Browse files
committed
C#: Convert cs/uncontrolled-format-string tests to use test inline expectations.
1 parent 4093afb commit dda52a2

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

csharp/ql/test/query-tests/Security Features/CWE-134/ConsoleUncontrolledFormatString.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ public class Program
55
{
66
public static void Main()
77
{
8-
var format = Console.ReadLine();
8+
var format = Console.ReadLine(); // $ Source
99

1010
// BAD: Uncontrolled format string.
11-
var x = string.Format(format, 1, 2);
11+
var x = string.Format(format, 1, 2); // $ Alert
1212
}
1313
}

csharp/ql/test/query-tests/Security Features/CWE-134/UncontrolledFormatString.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ public class TaintedPathHandler : IHttpHandler
66
{
77
public void ProcessRequest(HttpContext ctx)
88
{
9-
String path = ctx.Request.QueryString["page"];
9+
String path = ctx.Request.QueryString["page"]; // $ Source
1010

1111
// BAD: Uncontrolled format string.
12-
String.Format(path, "Do not do this");
12+
String.Format(path, "Do not do this"); // $ Alert
1313

1414
// BAD: Using an IFormatProvider.
15-
String.Format((IFormatProvider)null, path, "Do not do this");
15+
String.Format((IFormatProvider)null, path, "Do not do this"); // $ Alert
1616

1717
// GOOD: Not the format string.
1818
String.Format("Do not do this", path);
@@ -29,6 +29,6 @@ public void ProcessRequest(HttpContext ctx)
2929
void OnButtonClicked()
3030
{
3131
// BAD: Uncontrolled format string.
32-
String.Format(box1.Text, "Do not do this");
32+
String.Format(box1.Text, "Do not do this"); // $ Alert
3333
}
3434
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
query: Security Features/CWE-134/UncontrolledFormatString.ql
2-
postprocess: utils/test/PrettyPrintModels.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql

csharp/ql/test/query-tests/Security Features/CWE-134/UncontrolledFormatStringBad.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public class HttpHandler : IHttpHandler
66

77
public void ProcessRequest(HttpContext ctx)
88
{
9-
string format = ctx.Request.QueryString["nameformat"];
9+
string format = ctx.Request.QueryString["nameformat"]; // $ Source
1010

1111
// BAD: Uncontrolled format string.
12-
FormattedName = string.Format(format, Surname, Forenames);
12+
FormattedName = string.Format(format, Surname, Forenames); // $ Alert
1313
}
1414
}

0 commit comments

Comments
 (0)