Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Support interpolated strings in StringBuilder.Append #15010

Merged
merged 5 commits into from
Dec 7, 2023

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Dec 5, 2023

This PR improves taint tracking in the StringBuilder class. StringBuilder.Append and AppendLine implements the special interpolated string handler pattern, which was previously not covered by our dataflow models. The PR adds a couple of missing dataflow summaries and extends the local taint tracking logic to handle the AST structure produced by the compiler.

Commit-by-commit review is suggested, the first commits only move existing and add new test cases.

This PR depends on the previously merged changes:

@github-actions github-actions bot added the C# label Dec 5, 2023
Copy link
Contributor

github-actions bot commented Dec 6, 2023

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

csharp

Generated file changes for csharp

  • Changes to framework-coverage-csharp.rst:
-    System,"``System.*``, ``System``",25,11890,67,9
+    System,"``System.*``, ``System``",25,11900,67,9
-    Totals,,25,13008,399,9
+    Totals,,25,13018,399,9
  • Changes to framework-coverage-csharp.csv:
- System,67,25,11890,,8,8,9,,,4,5,33,1,17,3,4,9946,1944
+ System,67,25,11900,,8,8,9,,,4,5,33,1,17,3,4,9952,1948

@tamasvajk tamasvajk changed the title C#: WIP: Support interpolated strings in StringBuilder.Append C#: Support interpolated strings in StringBuilder.Append Dec 6, 2023
@tamasvajk tamasvajk force-pushed the fix/stringbuilder-interpolation branch from 711325f to 0a42b3c Compare December 7, 2023 09:37
@tamasvajk tamasvajk force-pushed the fix/stringbuilder-interpolation branch from 0a42b3c to e0c9be3 Compare December 7, 2023 09:57
@tamasvajk tamasvajk marked this pull request as ready for review December 7, 2023 10:36
@tamasvajk tamasvajk requested a review from a team as a code owner December 7, 2023 10:36
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor changes needed.

- ["System.Text", "StringBuilder", False, "Append", "(System.UInt16)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.UInt32)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.UInt64)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[0]", "ReturnValue", "taint", "manual"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

"Argument[this]", "ReturnValue"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I made these changes, also marked them as value steps

- ["System.Text", "StringBuilder", False, "Append", "(System.UInt16)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.UInt32)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.UInt64)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[0]", "ReturnValue", "taint", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[0]", "Argument[this]", "taint", "manual"]
- ["System.Text", "StringBuilder", False, "Append", "(System.IFormatProvider,System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[1]", "ReturnValue", "taint", "manual"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

"Argument[this]", "ReturnValue"

@@ -97,6 +103,10 @@ extensions:
- ["System.Text", "StringBuilder", False, "AppendLine", "()", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.String)", "", "Argument[0]", "Argument[this]", "taint", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.String)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[0]", "ReturnValue", "taint", "manual"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

"Argument[this]", "ReturnValue"

@@ -97,6 +103,10 @@ extensions:
- ["System.Text", "StringBuilder", False, "AppendLine", "()", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.String)", "", "Argument[0]", "Argument[this]", "taint", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.String)", "", "Argument[this]", "ReturnValue", "value", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[0]", "ReturnValue", "taint", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[0]", "Argument[this]", "taint", "manual"]
- ["System.Text", "StringBuilder", False, "AppendLine", "(System.IFormatProvider,System.Text.StringBuilder+AppendInterpolatedStringHandler)", "", "Argument[1]", "ReturnValue", "taint", "manual"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

"Argument[this]", "ReturnValue"

@tamasvajk tamasvajk merged commit 51adcf5 into github:main Dec 7, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants