Valgrind yells about an uninitialised bytes

前端 未结 1 1627
温柔的废话
温柔的废话 2021-02-05 04:15

Valgrind throws me out this error:

==11204== Syscall param write(buf) points to uninitialised byte(s)
==11204==    at 0x4109033: write (in /lib/libc-2.13.so)
==1         


        
相关标签:
1条回答
  • 2021-02-05 04:23

    Your Request structure has arrays name1, name2, etc. which contain null-terminated strings. When you fill them, you don't write past the null terminator. Later when you write the structure to the file, valgrind complains because these bytes are uninitialized. There may also be other uninitialized bytes (for example, padding inserted by the compiler).

    This is not necessarily a problem, other than a small security issue: The previous contents of memory, which may hold sensitive information, will get written to the file.

    You can memset the structure to 0 before filling its fields to avoid this error.

    0 讨论(0)
提交回复
热议问题