Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.
2023-06-22 10:38:01 +02:00

54 lines
1.2 KiB
Plaintext

== How to fix it in .NET
=== Code examples
include::../../common/fix/code-rationale.adoc[]
==== Noncompliant code example
[source,csharp,diff-id=1,diff-type=noncompliant]
----
public class ExampleController : Controller
{
public void Run(string binary)
{
Process p = new Process();
p.StartInfo.FileName = binary;
p.Start();
}
}
----
==== Compliant solution
[source,csharp,diff-id=1,diff-type=compliant]
----
public class ExampleController : Controller
{
public void Run(string binary)
{
if (binary.Equals("/usr/bin/ls") || binary.Equals("/usr/bin/cat"))
{
// only ls and cat commands are authorized
Process p = new Process();
p.StartInfo.FileName = binary;
p.Start();
}
}
}
----
=== How does this work?
include::../../common/fix/introduction.adoc[]
include::../../common/fix/pre-approved-list.adoc[]
:sanitizationLib: System.Diagnostics.ProcessStartInfo
include::../../common/fix/sanitize-meta-characters.adoc[]
Here, using the `ProcessStartInfo` structure helps escaping the passed
arguments and internally creates a single string given to the operating system
when `System.Diagnostics.Process.Start()` is called.