Main Content

CERT C++: MSC41-C

Never hard code sensitive information

Since R2020a

Description

Rule Definition

Never hard code sensitive information.1

Polyspace Implementation

The rule checker checks for Hard coded sensitive data.

Examples

expand all

Hard coded sensitive data occurs when data that is potentially sensitive is directly exposed in the code, for instance, as string literals. The checker identifies data as sensitive from their use in certain functions such as password encryption functions.

Following data can be potentially sensitive.

Type of DataFunctions That Indicate Sensitive Nature of Information
Host name
  • sethostname, setdomainname, gethostbyname, gethostbyname2, getaddrinfo, gethostbyname_r, gethostbyname2_r (string argument)

  • inet_aton, inet_pton, inet_net_pton, inet_addr, inet_network (string argument)

  • mysql_real_connect, mysql_real_connect_nonblocking, mysql_connect (2nd argument)

Password
  • CreateProcessWithLogonW, LogonUser (1st argument)

  • mysql_real_connect, mysql_real_connect_nonblocking, mysql_connect (3rd argument)

Database
  • MySQL: mysql_real_connect, mysql_real_connect_nonblocking, mysql_connect (4th argument)

  • SQLite: sqlite3_open, sqlite3_open16, sqlite3_open_v2 (1st argument)

  • PostgreSQL: PQconnectdb

  • Microsoft SQL: SQLDriverConnect (3rd argument)

User name
  • getpw, getpwnam, getpwnam_r, getpwuid, getpwuid_r

Saltcrypt, crypt_r (2nd argument)
Cryptography keys and initialization vectors

OpenSSL:

  • EVP_CipherInit, EVP_EncryptInit, EVP_DecryptInit (3rd argument)

  • EVP_CipherInit_ex, EVP_EncryptInit_ex, EVP_DecryptInit_ex (4th argument)

Seed
  • srand, srandom, initstate (1st argument)

  • OpenSSL: RAND_seed, RAND_add

Risk

Information that is hardcoded can be queried from binaries generated from the code.

Fix

Avoid hard coding sensitive information.

Check Information

Group: Rule 48. Miscellaneous (MSC)

Version History

Introduced in R2020a


1 This software has been created by MathWorks incorporating portions of: the “SEI CERT-C Website,” © 2017 Carnegie Mellon University, the SEI CERT-C++ Web site © 2017 Carnegie Mellon University, ”SEI CERT C Coding Standard – Rules for Developing safe, Reliable and Secure systems – 2016 Edition,” © 2016 Carnegie Mellon University, and “SEI CERT C++ Coding Standard – Rules for Developing safe, Reliable and Secure systems in C++ – 2016 Edition” © 2016 Carnegie Mellon University, with special permission from its Software Engineering Institute.

ANY MATERIAL OF CARNEGIE MELLON UNIVERSITY AND/OR ITS SOFTWARE ENGINEERING INSTITUTE CONTAINED HEREIN IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.

This software and associated documentation has not been reviewed nor is it endorsed by Carnegie Mellon University or its Software Engineering Institute.