CWE Rule 766
Description
Rule Description
The software declares a critical variable, field, or member to be public when intended security policy requires it to be private.
Polyspace Implementation
The rule checker checks for Critical data member is not private.
Examples
Critical data member is not private
This issue occurs when you declare a critical nonstatic data member of a class to be
public
. By default, Polyspace® assumes that no data member is critical. Specify the critical data members in
your code by using the code behavior CRITICAL_DATA
. See Specifying Critical Data Members. If you do not specify
any critical data members, Polyspace raises a warning during the analysis.
Declaring the critical data members as public
allows the clients of a
class to modify critical data members. You can inadvertently introduce vulnerabilities when
critical data members are public. The vulnerabilities of such code are difficult to find and
time-consuming to fix.
To fix this defect, determine which data members are critical and declare them as
private
or protected
.
This defect checker requires a list of critical data members to be externally specified. Even if you enable checking of CWE rules, this checker is not enabled unless you also specify a list of critical data members. See Modify Bug Finder Checkers Through Code Behavior Specifications.
#include <string.h> #define MAX_PASSWORD_LENGTH 15 #define MAX_USERNAME_LENGTH 15 class UserAccount { public: UserAccount(char *username, char *password) { //... } int authorizeAccess(char *username, char *password) { //... } char username[MAX_USERNAME_LENGTH+1]; //Noncompliant char password[MAX_PASSWORD_LENGTH+1]; //Noncompliant };
In this example, the data members username
and
password
are declared as public
. Specify these
variables as critical in a code behavior XML
file:
<specifications> <members> <member name="password" kind="variable"> <behavior name="CRITICAL_DATA"/> </member> <member name="username" kind="variable"> <behavior name="CRITICAL_DATA"/> </member> </members> </specifications>
To fix this defect, declare the critical variables as
private
#include <string.h> #define MAX_PASSWORD_LENGTH 15 #define MAX_USERNAME_LENGTH 15 class UserAccount { public: UserAccount(char *username, char *password) { //... } int authorizeAccess(char *username, char *password) { //... } private: char username[MAX_USERNAME_LENGTH+1]; char password[MAX_PASSWORD_LENGTH+1]; };
Check Information
Category: Permission Issues |
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)