函數已過時,不能保證指針是有效的,或引用的內存可以安全使用。
不使用 IsBadXXXPtr() 類的函數有多種原因。這些函數是:
1) 非線程安全的。
2) 通常與由于其探測無效內存地址而導致的崩潰有關。
3) 被錯誤地認為在異常條件中執行正確的錯誤處理。
例:以下代碼使用 IsBadWritePtr() 嘗試避免錯誤的內存寫入。
if (IsBadWritePtr(ptr, length))
{
[handle error]
}
[1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A9 Application Denial of Service
[2] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP6080 CAT II
[3] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP6080 CAT II
[4] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 730
[5] IsBadWritePtr Function Microsoft
[6] Raymond Chen IsBadXxxPtr should really be called CrashProgramRandomly
[7] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.9