Use of Invariant Value in Dynamically Changing Context

The product uses a constant value, name, or reference, but this value can (or should) vary across different environments.


The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

The following code is an example of an internal hard-coded password in the back-end:

int VerifyAdmin(char *password) {

  if (strcmp(password, "Mew!")) {

    printf("Incorrect Password!\n");

  printf("Entering Diagnostic Mode...\n");

int VerifyAdmin(String password) {
  if (!password.equals("Mew!")) {
  //Diagnostic Mode

Every instance of this program can be placed into diagnostic mode with the same password. Even worse is the fact that if this program is distributed as a binary-only distribution, it is very difficult to change that password or disable this "functionality."

Example Two

This code assumes a particular function will always be found at a particular address. It assigns a pointer to that address and calls the function.

int (*pt2Function) (float, char, char)=0x08040000;
int result2 = (*pt2Function) (12, 'a', 'b');
// Here we can inject code to execute.

The same function may not always be found at the same memory address. This could lead to a crash, or an attacker may alter the memory at the expected address, leading to arbitrary code execution.

See Also

Comprehensive Categorization: Randomness

Weaknesses in this category are related to randomness.

Random Number Issues

Weaknesses in this category are related to a software system's random number generation.

SFP Primary Cluster: Predictability

This category identifies Software Fault Patterns (SFPs) within the Predictability cluster.

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Weaknesses Introduced During Implementation

This view (slice) lists weaknesses that can be introduced during implementation.

Weaknesses Introduced During Design

This view (slice) lists weaknesses that can be introduced during design.

Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.