MISRAC2012-Rule-1.3_t
In this section:
Synopsis
(Required) There shall be no occurrence of undefined or critical unspecified behavior.
Enabled by default
Yes
Severity/Certainty
High/Medium

Full description
A call to memcpy or memmove causes the memory to overrun.
Coding standards
- CWE 119
Improper Restriction of Operations within the Bounds of a Memory Buffer
- CWE 120
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
- CWE 121
Stack-based Buffer Overflow
- CWE 122
Heap-based Buffer Overflow
- CWE 124
Buffer Underwrite ('Buffer Underflow')
- CWE 126
Buffer Over-read
- CWE 127
Buffer Under-read
- CWE 805
Buffer Access with Incorrect Length Value
- CWE 676
Use of Potentially Dangerous Function
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
void func()
{
int size = 10;
int arr1[10];
int arr2[11];
memcpy(arr2, arr1, sizeof(int) * (size + 1));
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
#include <string.h>
void func()
{
int arr[10];
int * ptr = (int *)malloc(sizeof(int) * 10);
memcpy(ptr, arr, sizeof(int) * 10);
}