An infinite loop occurs when a program's iteration logic contains an exit condition that can never be satisfied, causing the loop to run indefinitely and consume system resources.

This vulnerability typically stems from flawed loop logic where the condition for termination is incorrectly defined. Common causes include using a loop counter that never updates, checking against a variable that doesn't change within the loop body, or creating circular dependencies where the exit state becomes mathematically impossible to reach. Developers might introduce these errors through simple typos, incorrect operator usage, or misunderstanding how loop variables interact with other parts of the code. When an infinite loop executes, it can lead to denial of service by exhausting CPU cycles, memory, or other finite resources, potentially freezing the application or the entire system. To prevent this, always validate that loop control variables are properly modified inside the loop and that exit conditions are based on values that will eventually change. Using timeouts, circuit breakers, or defensive programming techniques like maximum iteration limits can provide safety nets for unexpected logic errors.
Impact: DoS: Resource Consumption (CPU)DoS: Resource Consumption (Memory)DoS: Amplification
An infinite loop will cause unexpected consumption of resources, such as CPU cycles or memory. The software's operation may slow down, or cause a long time to respond.
c
// create socket to connect to server* servsock = socket( AF_INET, SOCK_STREAM, 0); memset( &servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(port); servaddr.sin_addr.s_addr = inet_addr(hostaddr);
c
c
// read and process messages* ...}
cc
// initialize number of attempts counter* int count = 0; do { ```
c
// read and process messages* ...}
cjava
// get inventory count for book* int inventoryCount = inventory.getIventoryCount(bookISBN);
java
javajava
// validate rateSold variable* if (rateSold < 1) { ``` return isReorder; } ... }