Why electric fence/Valgrind is unable to catch this buffer-overflow issue?

前端 未结 5 2147
忘掉有多难
忘掉有多难 2021-02-10 16:11

I have created a buggy program - buggy.c - this is a buffer-overflow scenario for buffer t. You can see that I am writing more than 5 indexes. It works fine. It never throws me

5条回答
  •  萌比男神i
    2021-02-10 16:38

    To detect out-of-bounds accesses in statically allocated memory (i.e. on the stack), you can use a static code analysis tool.

    One that we've just begun to use at work is Klocwork

    As mentioned on the Valgrind wiki page (under limitations of memcheck), it can't detect out of bound accesses on statically allocated memory. Quoting from the wiki:

    The experimental valgrind tool exp-sgcheck has been written to address this limitation in Memcheck. It will detect array overrun errors provided the first access to an array is within the array bounds.

提交回复
热议问题