rspec/rules/S5883/csharp/rule.adoc

78 lines
1.7 KiB
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
[source,csharp]
----
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace WebApplicationDotNetCore.Controllers
{
public class NoncompliantController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Run(string args)
{
Process p = new Process();
p.StartInfo.FileName = "/usr/bin/file.exe";
p.StartInfo.Arguments = args; // Noncompliant
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.Dispose();
return View();
}
}
}
----
== Compliant Solution
[source,csharp]
----
using System.Diagnostics;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;
namespace WebApplicationDotNetCore.Controllers
{
public class CompliantController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Run(string arg)
{
Process p = new Process();
p.StartInfo.FileName = "/usr/bin/file.exe";
p.StartInfo.ArgumentList.Add(arg); // Compliant
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.Dispose();
return View();
}
}
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]