Skip to content

Don't pass local stack addresses to callers! #118

@fdgonthier

Description

@fdgonthier

It's kind of a miracle this worked at all:

uint8_t *pucBuffer[1500];

This allocates a large buffer on the stack, which is alright on its own, but then the address of this buffer is returned to the caller:

https://github.com/esmaxness/rinasense/blob/ee1163fa9967cd4c56704147991c7bbde73afcbe/components/Enrollment/SerdesMsg.c#L377

This is a big NO, and Valgrind is freaking out, justifiably so:

==86136== Thread 1:
==86136== Invalid read of size 8
==86136==    at 0x484A345: memmove (vg_replace_strmem.c:1382)
==86136==    by 0x486E367: prvRibdEncodeCDAP (Ribd.c:524)
==86136==    by 0x486FDB9: xRibdSendRequest (Ribd.c:1154)
==86136==    by 0x486953A: vFlowAllocatorFlowRequest (FlowAllocator.c:290)
==86136==    by 0x48707E1: prvConnect (RINA_API.c:316)
==86136==    by 0x48708AF: RINA_flow_alloc (RINA_API.c:352)
==86136==    by 0x10A4A4: main (test_linux.c:35)
==86136==  Address 0x1ffeffc870 is on thread 1's stack
==86136==  12328 bytes below stack pointer
==86136== 
==86136== Invalid read of size 8
==86136==    at 0x484A35F: memmove (vg_replace_strmem.c:1382)
==86136==    by 0x486E367: prvRibdEncodeCDAP (Ribd.c:524)
==86136==    by 0x486FDB9: xRibdSendRequest (Ribd.c:1154)
...

The stack buffer is also too big to deal with for Arduino so I need to change this code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions