R
R
ramir2019-07-13 11:50:57
C++ / C#
ramir, 2019-07-13 11:50:57

How to find a buffer overflow in C?

Hello!
I'm not strong in C and microcontrollers, so please don't kick me too hard.
The situation is as follows: I have a hung (logically, otherwise the watchdog would restart) microcontroller. The firmware is written in C. I connected with a debugger, paused the execution and looked at the state of the variables in memory. A large number of initialized, global variables (usually module contexts) contain some kind of rubbish. I come to the conclusion that somewhere I am accessing non-existent elements of one of the buffers. It was not possible to detect by typing and comparing the addresses of variables, the program is quite large.
Microcontroller: nRF52840
IDE: Segger embedded studio
Questions:
1. How do you usually look for such errors?
2. The situation happens quite rarely, is it possible to somehow remove the ladies of memory for further analysis? I know for sure that it is possible with the help of nrfutil, but it is not clear how to work with this further.
3. Maybe there are some tools for visualizing memory (variables in it), since all my code is without dynamic memory allocation.
4. Maybe there are some tools that can find similar situations by static code analysis.
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question