Is it secure to use malloc?

前端 未结 12 746
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 04:18

Somebody told me that allocating with malloc is not secure anymore, I\'m not a C/C++ guru but I\'ve made some stuff with malloc and C/C++. Does anyone know about what risks

12条回答
  •  时光说笑
    2021-01-05 05:13

    Perhaps the person was referring to the possibility of accessing data via malloc()?

    Malloc doesn't affect the contents of the region that it provides, so it MAY be possible to collect data from other processes by mallocing a large area and then scanning the contents.

    free() doesn't clear memory either so data paced into dynamically allocated buffers is, in principle, accessible.

    I know someone who, many years ago admittedly, exploited malloc to create an inter-process communication scheme when he found that mallocs of equal size would return the address of the most recently free'd block.

提交回复
热议问题