CWE Rule 532
Description
Rule Description
Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information.
Polyspace Implementation
The rule checker checks for Sensitive data printed out.
Examples
Sensitive data printed out
This issue occurs when print functions such as stdout
or
stderr
print sensitive information.
The checker considers the following as sensitive information:
Return values of password manipulation functions such as
getpw
,getpwnam
orgetpwuid
.Input values of functions such as the Windows®-specific function
LogonUser
.
Printing sensitive information, such as passwords or user information, allows an attacker additional access to the information.
One fix for this defect is to not print out sensitive information.
If you are saving your logfile to an external file, set the file permissions so that attackers cannot access the logfile information.
#include <sys/types.h> #include <pwd.h> #include <stdio.h> #include <string.h> #include <unistd.h> extern void verify_null(const char* buf); void bug_sensitivedataprint(const char * my_user) { struct passwd* result, pwd; long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); char buf[1024] = ""; getpwnam_r(my_user, &pwd, buf, bufsize, &result); puts("Name\n"); puts(pwd.pw_name); puts("PassWord\n"); puts(pwd.pw_passwd); //Noncompliant memset(buf, 0, sizeof(buf)); verify_null(buf); }
In this example, Bug Finder flags puts
for
printing out the password pwd.pw_passwd
.
One possible correction is to obfuscate the password information so that the information is not visible.
#include <sys/types.h> #include <pwd.h> #include <stdio.h> #include <string.h> #include <unistd.h> extern void verify_null(const char* buf); void sensitivedataprint(const char * my_user) { struct passwd* result, pwd; long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); char buf[1024] = ""; getpwnam_r(my_user, &pwd, buf, bufsize, &result); puts("Name\n"); puts(pwd.pw_name); puts("PassWord\n"); puts("XXXXXXXX\n"); memset(buf, 0, sizeof(buf)); verify_null(buf); }
Check Information
Category: Others |
Version History
Introduced in R2024a
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 (한국어)