mirror of
https://github.com/github/codeql.git
synced 2026-04-26 01:05:15 +02:00
Add implementation and tests
This commit is contained in:
committed by
carldybdahl-microsoft
parent
7f56c67544
commit
44e6691e6d
16
csharp/ql/src/Bad Practices/PathCombine.qhelp
Normal file
16
csharp/ql/src/Bad Practices/PathCombine.qhelp
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
<overview>
|
||||
<p><code>Path.Combine</code> may silently drop its earlier arguments if its later arguments are absolute paths. E.g. <code>Path.Combine("C:\\Users\\Me\\Documents", "C:\\Program Files\\") == "C:\\Program Files"</code>.</p>
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
<p>Use <code>Path.Join</code> instead.</p>
|
||||
</recommendation>
|
||||
<references>
|
||||
|
||||
|
||||
</references>
|
||||
</qhelp>
|
||||
7
csharp/ql/src/Bad Practices/PathCombine.ql
Normal file
7
csharp/ql/src/Bad Practices/PathCombine.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.frameworks.System
|
||||
|
||||
from MethodCall call
|
||||
where call.getTarget().hasFullyQualifiedName("System.IO", "Path", "Combine")
|
||||
select call, "Path.Combine may silently discard its initial arguments if the latter are absolute paths. Use Path.Join to consistently join them."
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.IO;
|
||||
|
||||
class EmptyCatchBlock
|
||||
{
|
||||
void bad()
|
||||
{
|
||||
Path.Combine(@"C:\Users", @"C:\Program Files");
|
||||
}
|
||||
|
||||
void good()
|
||||
{
|
||||
Path.Join(@"C:\Users", @"C:\Program Files");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
| PathCombine.cs:7:9:7:55 | catch (...) {...} | Path.Combine may silently discard its initial arguments if the latter are absolute paths. Use Path.Join to consistently join them. |
|
||||
@@ -0,0 +1 @@
|
||||
Bad Practices/PathCombine.ql
|
||||
@@ -0,0 +1,2 @@
|
||||
semmle-extractor-options: /nostdlib /noconfig
|
||||
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
|
||||
Reference in New Issue
Block a user