CWE-835: Infinite Loop
Loop with Unreachable Exit Condition
The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.
How it's found
Infinite Loop is typically found by tracing untrusted input from where it enters the system to the point where it is used without the check or neutralization this weakness describes, combining manual code review with dynamic testing.
Vulnerable vs. safe
// create socket to connect to server
// keep trying to establish connection to the server
// close socket and return success or failure
// establish connection to server
// if connected then read and process messages from server
// read and process messages...connected = connect(servsock, (struct sockaddr *)&servaddr, sizeof(servaddr));if (connected > -1) {}...int servsock;int connected;struct sockaddr_in servaddr;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);do {} while (connected < 0);...int processMessagesFromServer(char *hostaddr, int port) {}// initialize number of attempts counter
// keep trying to establish connection to the server
// up to a maximum number of attempts
// close socket and return success or failure
// establish connection to server
// increment counter
// if connected then read and process messages from server
// read and process messages...connected = connect(servsock, (struct sockaddr *)&servaddr, sizeof(servaddr));count++;if (connected > -1) {}...int count = 0;do {} while (connected < 0 && count < MAX_ATTEMPTS);...int processMessagesFromServer(char *hostaddr, int port) {}Consequences
- 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.
Where this fits in a TurboPentest engagement
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Frequently asked questions
What is CWE-835?
The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.
How do you find Infinite Loop?
Infinite Loop is typically found by tracing untrusted input from where it enters the system to the point where it is used without the check or neutralization this weakness describes, combining manual code review with dynamic testing.
What is the impact of CWE-835?
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.
Does TurboPentest test for Infinite Loop?
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Related CWEs
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a $99 pentest