Skip to content

Commit 0a4f2e8

Browse files
authored
Merge pull request #813 from calumgrant/cs/sb-append-chars
C#: Fix FP in cs/call-to-object-tostring
2 parents 63ed0c5 + c213cd4 commit 0a4f2e8

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

change-notes/1.20/analysis-csharp.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
| Dereferenced variable is always null (cs/dereferenced-value-is-always-null) | Improved results | The query has been rewritten from scratch, and the analysis is now based on static single assignment (SSA) forms. The query is now enabled by default in LGTM. |
1616
| Dereferenced variable may be null (cs/dereferenced-value-may-be-null) | Improved results | The query has been rewritten from scratch, and the analysis is now based on static single assignment (SSA) forms. The query is now enabled by default in LGTM. |
1717
| SQL query built from user-controlled sources (cs/sql-injection), Improper control of generation of code (cs/code-injection), Uncontrolled format string (cs/uncontrolled-format-string), Clear text storage of sensitive information (cs/cleartext-storage-of-sensitive-information), Exposure of private information (cs/exposure-of-sensitive-information) | More results | Data sources have been added from user controls in `System.Windows.Forms`. |
18-
18+
| Use of default ToString() (cs/call-to-object-tostring) | Fewer false positives | Results have been removed for `char` arrays passed to `StringBuilder.Append()`, which were incorrectly marked as using `ToString`. |
19+
1920
## Changes to code extraction
2021

2122
* Fix extraction of `for` statements where the condition declares new variables using `is`.

csharp/ql/src/semmle/code/csharp/commons/Strings.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class ImplicitToStringExpr extends Expr {
2828
m = p.getCallable()
2929
|
3030
m = any(SystemTextStringBuilderClass c).getAMethod() and
31-
m.getName().regexpMatch("Append(Line)?")
31+
m.getName().regexpMatch("Append(Line)?") and
32+
not p.getType() instanceof ArrayType
3233
or
3334
p instanceof StringFormatItemParameter and
3435
not p.getType() = any(ArrayType at |

csharp/ql/test/query-tests/Useless Code/DefaultToString/DefaultToString.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ void M()
2626

2727
C c = new D();
2828
Console.WriteLine(c); // GOOD
29+
30+
var sb = new StringBuilder();
31+
sb.Append(new char[] { 'a', 'b', 'c' }, 0, 3); // GOOD
2932
}
3033

3134
class A

0 commit comments

Comments
 (0)