Description
The source code contains a block that does not contain any code, i.e., the block is empty.
Empty code blocks can occur in the bodies of conditionals, function or method definitions, exception handlers, etc. While an empty code block might be intentional, it might also indicate incomplete implementation, accidental code deletion, unexpected macro expansion, etc. For some programming languages and constructs, an empty block might be allowed by the syntax, but the lack of any behavior within the block might violate a convention or API in such a way that it is an error.
Potential Impact
Other
Reduce Reliability
Demonstrative Examples
public class Main {
public static void main(String[] args) {
int a = 1;
int b = 0;
int c = 0;
try {
c = a / b;
} catch(ArithmeticException ae) {
}
}
}public class Main {
public static void main(String[] args) {
int a = 1;
int b = 0;
int c = 0;
try {
c = a / b;
} catch(ArithmeticException ae) {
log.error("Divided by zero detected, setting to -1.");
c = -1;
}
}
}synchronized(this) { }public void setID(int ID){synchronized(this){this.ID = ID;}}Detection Methods
- Automated Static Analysis High — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
Related Weaknesses
Frequently Asked Questions
What is CWE-1071?
CWE-1071 (Empty Code Block) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The source code contains a block that does not contain any code, i.e., the block is empty.
How can CWE-1071 be exploited?
Attackers can exploit CWE-1071 (Empty Code Block) to reduce reliability. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-1071?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-1071?
CWE-1071 is classified as a Base-level weakness (Medium abstraction). Its actual severity depends on the specific context and how the weakness manifests in your application.