Skip to content

Commit e0d2b0a

Browse files
committed
sim: fix vofrk 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 2334484 commit e0d2b0a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

arch/sim/src/sim/sim_vfork.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@
8282
*
8383
****************************************************************************/
8484

85+
#ifdef CONFIG_SIM_ASAN
86+
__attribute__((no_sanitize_address))
87+
#endif
8588
pid_t up_vfork(const xcpt_reg_t *context)
8689
{
8790
struct tcb_s *parent = this_task();
8891
struct task_tcb_s *child;
92+
unsigned char *pout;
93+
unsigned char *pin;
8994
xcpt_reg_t newsp;
9095
xcpt_reg_t newfp;
9196
xcpt_reg_t newtop;
@@ -130,7 +135,9 @@ pid_t up_vfork(const xcpt_reg_t *context)
130135
newtop = (xcpt_reg_t)child->cmn.stack_base_ptr +
131136
child->cmn.adj_stack_size;
132137
newsp = newtop - stackutil;
133-
memcpy((void *)newsp, (const void *)context[JB_SP], stackutil);
138+
pout = (unsigned char *)newsp;
139+
pin = (unsigned char *)context[JB_SP];
140+
while (stackutil-- > 0) *pout++ = *pin++;
134141

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

0 commit comments

Comments
 (0)