Skip to content

Commit 3e66498

Browse files
PwnVerseanchao
authored andcommitted
Fix Overlap Handling in sim_copyfullstate to Prevent Undefined Behavior
1 parent 4d63921 commit 3e66498

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

arch/sim/src/sim/sim_copyfullstate.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <nuttx/config.h>
2828

2929
#include <stdint.h>
30+
#include <string.h>
3031
#include <arch/irq.h>
3132

3233
#include "sim_internal.h"
@@ -45,18 +46,13 @@
4546

4647
void sim_copyfullstate(xcpt_reg_t *dest, xcpt_reg_t *src)
4748
{
48-
int i;
49-
5049
/* In the sim model, the state is copied from the stack to the TCB,
5150
* but only a reference is passed to get the state from the TCB. So the
5251
* following check avoids copying the TCB save area onto itself:
5352
*/
5453

5554
if (src != dest)
5655
{
57-
for (i = 0; i < XCPTCONTEXT_REGS; i++)
58-
{
59-
*dest++ = *src++;
60-
}
56+
memmove(dest, src, XCPTCONTEXT_REGS * sizeof(xcpt_reg_t));
6157
}
6258
}

0 commit comments

Comments
 (0)