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
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)