CWE-1041: Use of Redundant Code

Description

The product has multiple functions, methods, procedures, macros, etc. that contain the same code.

Submission Date :

July 2, 2018, midnight

Modification Date :

2023-06-29 00:00:00+00:00

Organization :

MITRE
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.

Example Vulnerable Codes

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.




// complex math equationssurface_area = pi * r * s + pi * Math.pow(r, 2);

// a complex set of mathsurface_area = pi * r * s + pi * Math.pow(r, 2);
double s = 10.0;double r = 1.0;double pi = 3.14159;double surface_area;if(r > 0.0) {}if(r > 1.0) {}
public static void main(String[] args) {}
public class Main {}

It is recommended to place the complex math into its own function and then call that function whenever necessary.



//complex math equationsdouble pi = Math.PI;double surface_area = pi * r * s + pi * Math.pow(r, 2);return surface_area;
private double ComplexMath(double r, double s) {}

surface_area = ComplexMath(r, s);
surface_area = ComplexMath(r, s);
double s = 10.0;double r = 1.0;double surface_area;if(r > 0.0) {}if(r > 1.0) {}
public static void main(String[] args) {}
public class Main {}

Related Weaknesses

This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.

Visit http://cwe.mitre.org/ for more details.

© cvefeed.io
Latest DB Update: Nov. 22, 2024 2:32