...
Code Block | ||||
---|---|---|---|---|
| ||||
void squirrel_away(char **ptr_param) { char local[10]; /* Initialize array */ *ptr_param = local; } void rodent() { char *ptr; squirrel_away(&ptr); /* ptr is live but invalid here */ } |
Compliant Solution
The variable local
does not go out of scope for the entire program so, ptr
is live and valid in the function rodent()
.
Code Block | ||||
---|---|---|---|---|
| ||||
char local[10];
void squirrel_away(char **ptr_param) {
/* Initialize array */
*ptr_param = local;
}
void rodent() {
char *ptr;
squirrel_away(&ptr);
/* ptr is live but invalid here */
}
|
Risk Assessment
Referencing an object outside of its lifetime can result in an attacker being able to run arbitrary code.
...