Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fdgonthier opened this issue Sep 22, 2022 · 0 comments
Open

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

fdgonthier opened this issue Sep 22, 2022 · 0 comments

Comments

@fdgonthier
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant