The product allocates memory based on an untrusted, large size value, but it does not ensure that the size is within expected limits, allowing arbitrary amounts of memory to be allocated.
Impact: DoS: Resource Consumption (Memory)
Not controlling memory allocation can result in a request for too much system memory, possibly leading to a crash of the application due to out-of-memory conditions, or the consumption of a large amount of memory on the system.
c
/* ignore integer overflow (CWE-190) for this example /
cjavacint proc_msg(char *s, int msg_len) {
// Note space at the end of the string - assume all strings have preamble with space* int pre_len = sizeof("preamble: "); char buf[pre_len - msg_len];
c
char *s = "preamble: message\n"; char *sl = strchr(s, ':'); // Number of characters up to ':' (not including space) int jnklen = sl == NULL ? 0 : sl - s; // If undefined pointer, use zero length int ret_val = proc_msg ("s", jnklen); // Violate assumption of preamble length, end up with negative value, blow out stack
perlint proc_msg(char *s, int msg_len) {
cint proc_msg(char *s, int msg_len) {
c