When should SecureZeroMemory() be used?

后端 未结 2 1724
深忆病人
深忆病人 2021-01-20 18:41

I found some sample code that looks like:

addrinfo hints;
SecureZeroMemory(&hints, sizeof(hints));

Is there a reason to use SecureZeroM

2条回答
  •  星月不相逢
    2021-01-20 19:43

    If (for example) the variable is not used anymore in the present scope (or in any other scenario where the compiler proves it doesn't change the internal coherence the program), the compiler could optimize away the zeroing statement. For security-critical memory, this could compromise the security of the application when it comes to external processes examining the memory of yours. SecureZeroMemory is written so that it does not get optimized away.

    I can't tell for sure why this particular code snippet chooses that function over other methods of zeroing a memory range. It could be a misunderstanding of its purpose by the code's author or a misguided company policy.

提交回复
热议问题