This vulnerability occurs when a program incorrectly frees a memory pointer that no longer points to the beginning of the allocated heap buffer, often due to pointer arithmetic.
This issue typically happens when you allocate memory using functions like `malloc()`, `calloc()`, or `realloc()`, and then later modify the pointer—for example, by incrementing it to traverse a data structure. When you later pass this offset pointer to `free()`, the memory manager cannot correctly identify the original memory block's metadata, leading to heap corruption. This corruption can cause immediate crashes, unpredictable behavior, or even create opportunities for attackers to manipulate program data or execution flow. To prevent this, always ensure you free the exact pointer returned by the allocation function, or use a separate tracking variable to preserve the original starting address.
Impact: Modify MemoryDoS: Crash, Exit, or RestartExecute Unauthorized Code or Commands
Strategy: Libraries or Frameworks
c
/* matched char, free string and return success / free(str); return SUCCESS;}
cc
/* matched char, free string and return success / free(str); return SUCCESS;}
cc//hardcode input length for simplicity* char* input = (char*) malloc(40*sizeof(char)); char tok; char sep = " \t";
c
c//hardcode input length for simplicity* char* input = (char*) malloc(40*sizeof(char)); char *tok, command; char sep = " \t";
c
c