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
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
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?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
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 pentest