rspec/rules/S4000/csharp/rule.adoc

55 lines
1.0 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
Pointer and unmanaged function pointer types such as `IntPtr`, `UIntPtr`, ``++int*++`` etc. are used to access unmanaged memory, usually in order to use C or {cpp} libraries. If such a pointer is not secured by making it `private`, `internal` or `readonly`, it can lead to a vulnerability allowing access to arbitrary locations.
2021-04-28 16:49:39 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
namespace MyLibrary
{
public class MyClass
{
public IntPtr myPointer; // Noncompliant
protected UIntPtr myOtherPointer; // Noncompliant
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
namespace MyLibrary
{
public class MyClass
{
private IntPtr myPointer;
protected readonly UIntPtr myOtherPointer;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Makes this pointer readonly, internal or private.
=== Highlighting
The pointer declaration
endif::env-github,rspecator-view[]