CWE Rule 489
Description
Rule Description
The application is deployed to unauthorized actors with debugging code still enabled or active, which can create unintended entry points or expose sensitive information.
Polyspace Implementation
The rule checker checks for Use of a forbidden function.
Examples
This issue occurs when you use a function that appears in a blocklist of forbidden functions. To create the blocklist:
List functions in an XML file in a specific syntax.
Copy the template file
code-behavior-specifications-template.xml
from the folder
to a writable location and modify the file. Enter each function in the file using the following syntax after existing similar entries:polyspaceroot
\polyspace\verifier\cxxwhere<function name="funcname"> <behavior name="FORBIDDEN_FUNC"/> </function>
is the name of the function you want to block.funcname
Specify this XML file as argument for the option
-code-behavior-specifications
. See Flag Deprecated or Unsafe Functions, Keywords, or Macros Using Bug Finder Checkers.
A function might be blocked for one of these reasons:
The function can lead to many situations where the behavior is undefined leading to security vulnerabilities, and a more secure function exists.
You can forbid functions that are not explicitly checked by existing checkers such as
Use of dangerous standard function
orUse of obsolete standard function
.The function is being deprecated as part of a migration, for instance, from C++98 to C++11.
As part of a migration, you can make a list of functions that need to be replaced and use this checker to identify their use.
Replace the blocked function with an allowed function.
When rolling out this checker to a group, project or organization, create a list of blocked functions and their replacements so that results reviewers can consult the list and make appropriate replacements.
This defect checker requires a blocklist of functions to be specified. Even if you specify the checker using the option Find defects (-checkers)
, it is not enabled unless you also specify the blocklist. See Flag Deprecated or Unsafe Functions, Keywords, or Macros Using Bug Finder Checkers.
#include <csignal>
#include <iostream>
namespace
{
volatile std::sig_atomic_t gSignalStatus;
}
void signal_handler(int signal)
{
gSignalStatus = signal;
}
int main()
{
// Install a signal handler
std::signal(SIGINT, signal_handler); //Noncompliant
std::cout << "SignalValue: " << gSignalStatus << '\n';
std::cout << "Sending signal " << SIGINT << '\n';
std::raise(SIGINT);
std::cout << "SignalValue: " << gSignalStatus << '\n';
}
Suppose you want to deprecate the
std::signal
function. Define the following code
behavior specifications in XML
format:
<?xml version="1.0" encoding="UTF-8"?>
<specifications xmlns="http://www.mathworks.com/PolyspaceCodeBehaviorSpecifications">
<functions>
<function name="std::signal">
<behavior name="FORBIDDEN_FUNC"/>
</function>
</functions>
</specifications>
-code-behavior-specifications
.In the analysis results, all uses of the std::signal
function are
flagged by this checker.
class orderedPair {
int var1;
int var2;
public:
orderedPair() {
var1 = 0;
var2 = 0;
}
orderedPair(int arg1, int arg2) {
var1 = arg1;
var2 = arg2;
}
orderedPair& operator=(const orderedPair& rhs) {
var1 = rhs.var1;
var2 = rhs.var2;
return *this;
}
orderedPair& operator+(orderedPair& rhs) {
var1 += rhs.var1;
var2 += rhs.var2;
return *this;
}
};
void main() {
int one=1, zero=0, sum;
orderedPair firstOrderedPair(one, one);
orderedPair secondOrderedPair(zero, one);
orderedPair sumPair;
sum = zero + one;
sumPair = firstOrderedPair + secondOrderedPair; //Noncompliant
}
Suppose you want to identify all the locations where operator overloads in the orderedPair
class are used. Add the overloaded operators to the template XML file:
<?xml version="1.0" encoding="UTF-8"?>
<specifications xmlns="http://www.mathworks.com/PolyspaceCodeBehaviorSpecifications">
<functions>
<function name="orderedPair::operator=">
<behavior name="FORBIDDEN_FUNC"/>
</function>
<function name="orderedPair::operator+">
<behavior name="FORBIDDEN_FUNC"/>
</function>
</functions>
</specifications>
-code-behavior-specifications
.The analysis identifies all calls to the overloaded operators and flags their use. Using this method, you can distinguish specific overloads of an operator instead of searching for and browsing through all instances of the operator.
Check Information
Category: Bad Coding Practices |
Version History
Introduced in R2023a
See Also
External Websites
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)