967
}
public Worker(Channel ch, int nworkers) {
...
}
protected void activate() {
Runnable loop = new Runnable() {
public void run() {
try {
for (;;) {
Runnable r = ...;
r.run();
}
}
catch (InterruptedException ie) {
...
}
}
};
new Thread(loop).start();
}
}
There are no limits to runnables. Potentially an attacker could cause resource problems very
quickly.
Example 2:
This code allocates a socket and forks each time it receives a new connection.
Example Language: C (Bad)
sock=socket(AF_INET, SOCK_STREAM, 0);
while (1) {
newsock=accept(sock, ...);
printf("A connection has been accepted\n");
pid = fork();
}
The program does not track how many connections have been made, and it does not limit the
number of connections. Because forking is a relatively expensive operation, an attacker would be
able to cause the system to run out of CPU, processes, or memory by making a large number of
connections. Alternatively, an attacker could consume all available connections, preventing others
from accessing the system remotely.
Example 3:
In the following example a server socket connection is used to accept a request to store data on
the local file system using a specified filename. The method openSocketConnection establishes
a server socket to accept requests from a client. When a client establishes a connection to this
service the getNextMessage method is first used to retrieve from the socket the name of the file
to store the data, the openFileToWrite method will validate the filename and open a file to write to
on the local file system. The getNextMessage is then used within a while loop to continuously read
data from the socket and output the data to the file until there is no longer any data from the socket.
Example Language: C (Bad)
int writeDataFromSocketToFile(char *host, int port)
{
char filename[FILENAME_SIZE];
char buffer[BUFFER_SIZE];
int socket = openSocketConnection(host, port);
if (socket < 0) {
printf("Unable to open socket connection");
return(FAIL);
}
CWE Version 4.14
CWE-400: Uncontrolled Resource Consumption
CWE-400: Uncontrolled Resource Consumption