1875
CWE-1041: Use of Redundant Code
Weakness ID : 1041
Structure : Simple
Abstraction : Base
Description
The product has multiple functions, methods, procedures, macros, etc. that contain the same code.
Extended Description
This issue makes it more difficult to maintain the product, which indirectly affects security by
making it more difficult or time-consuming to find and/or fix vulnerabilities. For example, if there are
two copies of the same code, the programmer might fix a weakness in one copy while forgetting to
fix the same weakness in another copy.
Relationships
The table(s) below shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOr and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition, relationships such
as PeerOf and CanAlsoBe are defined to show similar weaknesses that may want to be explored.
Relevant to the view "Research Concepts" (CWE-1000)
Nature Type ID Name Page
ChildOf 710 Improper Adherence to Coding Standards 1549
Relevant to the view "Software Development" (CWE-699)
Nature Type ID Name Page
MemberOf 1006 Bad Coding Practices 2422
Weakness Ordinalities
Indirect :
Applicable Platforms
Language : Not Language-Specific (Prevalence = Undetermined)
Common Consequences
Scope Impact Likelihood
Other Reduce Maintainability
Potential Mitigations
Phase: Implementation
Merge common functionality into a single function and then call that function from across the
entire code base.
Demonstrative Examples
Example 1:
In the following Java example the code performs some complex math when specific test conditions
are met. The math is the same in each case and the equations are repeated within the code.
Unfortunately if a future change needs to be made then that change needs to be made in all
locations. This opens the door to mistakes being made and the changes not being made in the
same way in each instance.
Example Language: Java (Bad)
public class Main {
public static void main(String[] args) {
CWE Version 4.14
CWE-1042: Static Member Data Element outside of a Singleton Class Element
CWE-1042: Static Member Data Element outside of a Singleton Class Element