Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor edits; will need more wording updates

Every object has a storage duration that determines its lifetime: static, threadautomatic, or allocated dynamic.

[ISO/IEC 14882-2003] Section 3.8, "Object Lifetime" describes a number of situations in which trying to access an object outside of its lifetime leads to undefined behavior.

...

In this compliant solution, the variable local has static storage duration; consequently, ptr can be used to reference the local array within the rodent() function:

 

Code Block
bgColor#ccccff
langc
char local[10];
 
void squirrel_away(char **ptr_param) {
  /* Initialize array */
  *ptr_param = local;
}

void rodent(void) {
  char *ptr;
  squirrel_away(&ptr);
  /* ptr is valid in this scope */
}
 

Risk  Risk Assessment

Referencing an object outside of its lifetime can result in an attacker being able to run arbitrary code.

...

...

Bibliography

[Coverity 2007] 
[ISO/IEC 14882-2003]Sections 3.7, "Storage duration"; 3.8, "Object Lifetime"

...