Skip to content

Commit

Permalink
sim: fix vfork report error
Browse files Browse the repository at this point in the history
user_main: vfork() test
=================================================================
==3754757==ERROR: AddressSanitizer: stack-buffer-underflow on address 0xae9126f0 at pc 0x56845661 bp 0xae912570 sp 0xae912560
READ of size 1 at 0xae9126f0 thread T0
    #0 0x56845660 in memcpy string/lib_memcpy.c:44
    #1 0x56b70f61 in up_vfork sim/sim_vfork.c:133
    #2 0x567c0b85 in vfork (/home/ligd/platform/sim/nuttx/nuttx+0x26bb85)

0xae9126f0 is located 73456 bytes inside of 73728-byte region [0xae900800,0xae912800)
allocated by thread T0 here:
    #0 0xf7ab1c2f in __interceptor_posix_memalign ../../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:226

SUMMARY: AddressSanitizer: stack-buffer-underflow string/lib_memcpy.c:44 in memcpy

Signed-off-by: ligd <[email protected]>
  • Loading branch information
GUIDINGLI authored and xiaoxiang781216 committed Feb 11, 2023
1 parent a2097cf commit 7e3e99c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion arch/sim/src/sim/sim_vfork.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <errno.h>
#include <debug.h>

#include <nuttx/compiler.h>
#include <nuttx/sched.h>
#include <nuttx/arch.h>
#include <arch/irq.h>
Expand Down Expand Up @@ -82,10 +83,15 @@
*
****************************************************************************/

#ifdef CONFIG_SIM_ASAN
nosanitize_address
#endif
pid_t up_vfork(const xcpt_reg_t *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
unsigned char *pout;
unsigned char *pin;
xcpt_reg_t newsp;
xcpt_reg_t newfp;
xcpt_reg_t newtop;
Expand Down Expand Up @@ -130,7 +136,9 @@ pid_t up_vfork(const xcpt_reg_t *context)
newtop = (xcpt_reg_t)child->cmn.stack_base_ptr +
child->cmn.adj_stack_size;
newsp = newtop - stackutil;
memcpy((void *)newsp, (const void *)context[JB_SP], stackutil);
pout = (unsigned char *)newsp;
pin = (unsigned char *)context[JB_SP];
while (stackutil-- > 0) *pout++ = *pin++;

/* Was there a frame pointer in place before? */

Expand Down

0 comments on commit 7e3e99c

Please sign in to comment.