Skip to content

Commit

Permalink
Fix Overlap Handling in sim_copyfullstate to Prevent Undefined Behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
PwnVerse authored and anchao committed Jan 6, 2025
1 parent 4d63921 commit 3e66498
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions arch/sim/src/sim/sim_copyfullstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <nuttx/config.h>

#include <stdint.h>
#include <string.h>
#include <arch/irq.h>

#include "sim_internal.h"
Expand All @@ -45,18 +46,13 @@

void sim_copyfullstate(xcpt_reg_t *dest, xcpt_reg_t *src)
{
int i;

/* In the sim model, the state is copied from the stack to the TCB,
* but only a reference is passed to get the state from the TCB. So the
* following check avoids copying the TCB save area onto itself:
*/

if (src != dest)
{
for (i = 0; i < XCPTCONTEXT_REGS; i++)
{
*dest++ = *src++;
}
memmove(dest, src, XCPTCONTEXT_REGS * sizeof(xcpt_reg_t));
}
}

0 comments on commit 3e66498

Please sign in to comment.