Skip to content

Commit 7e3e99c

Browse files
GUIDINGLIxiaoxiang781216
authored andcommitted
sim: fix vfork report error
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 <liguiding1@xiaomi.com>
1 parent a2097cf commit 7e3e99c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

arch/sim/src/sim/sim_vfork.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <errno.h>
3232
#include <debug.h>
3333

34+
#include <nuttx/compiler.h>
3435
#include <nuttx/sched.h>
3536
#include <nuttx/arch.h>
3637
#include <arch/irq.h>
@@ -82,10 +83,15 @@
8283
*
8384
****************************************************************************/
8485

86+
#ifdef CONFIG_SIM_ASAN
87+
nosanitize_address
88+
#endif
8589
pid_t up_vfork(const xcpt_reg_t *context)
8690
{
8791
struct tcb_s *parent = this_task();
8892
struct task_tcb_s *child;
93+
unsigned char *pout;
94+
unsigned char *pin;
8995
xcpt_reg_t newsp;
9096
xcpt_reg_t newfp;
9197
xcpt_reg_t newtop;
@@ -130,7 +136,9 @@ pid_t up_vfork(const xcpt_reg_t *context)
130136
newtop = (xcpt_reg_t)child->cmn.stack_base_ptr +
131137
child->cmn.adj_stack_size;
132138
newsp = newtop - stackutil;
133-
memcpy((void *)newsp, (const void *)context[JB_SP], stackutil);
139+
pout = (unsigned char *)newsp;
140+
pin = (unsigned char *)context[JB_SP];
141+
while (stackutil-- > 0) *pout++ = *pin++;
134142

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

0 commit comments

Comments
 (0)