Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If the misaligned pointer is dereferenced, the program may terminate abnormally. On some architectures, the cast alone may cause a loss of information even if the value is not dereferenced if the types involved have differing alignment requirements.

...

In this noncompliant example, the char pointer &c is converted to the more strictly aligned int pointer ip. On some implementations, cp will not match &c. As a result, if a pointer to one object type is converted to a pointer to a different object type, the second object type must not require stricter alignment than the first.

...

Code Block
bgColor#ccccff
langc
#include <string.h>
 
struct foo_header {
  int len;
  /* ... */
};
  
void func(char *data, size_t offset) {
  struct foo_header header; 
  memcpy(&header, data + offset, sizeof(header));

  /* ... */
}

Exceptions

EXP36-EX0EX1: Some platforms, notably x86, have relaxed requirements with regard to pointer alignment. Using a pointer that is not properly aligned is correctly handled by the platform, although the platform may impose a performance penalty. On such a platform, improper pointer alignment is permitted, as it is an efficiency problem but not a security problem.

...

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...