C#

C#

Made by DeepSource

Audit required: Pointer arithmetic may point to incorrect memory location CS-A1013

Security
Major
a04 sans top 25 owasp top 10 cwe-119 cwe-120 cwe-122 cwe-788

C# allows you to use pointers via the unsafe construct. This also allows you to perform pointer arithmetic. While this may be useful to you, particularly if you're performing low-level operations, it is also possible that you may end up trying to access incorrect memory locations or regions that you aren't supposed to access. It is therefore recommended that you validate all the parameters and offsets that you're using when performing pointer arithmetic.

Bad Practice

var newPtr = oldPtr + offset;
*newPtr = value;

Recommended

if (offset > lb && offset < ub)
{
    var newPtr = oldPtr + offset;
    *newPtr = value;
}

Reference