該程序可能會間接引用一個 null 指針,從而引起 segmentation fault。
當違反程序員的一個或多個假設時,通常會出現 null 指針異常。具體來說,如果程序明確檢查過該指針為 null,但仍繼續間接引用該指針,則將出現 dereference-after-check 錯誤。此類錯誤通常是由于錯別字或程序員失察造成的。
大部分 null 指針問題會引起常規軟件的可靠性問題,但如果攻擊者能故意觸發一個 null 指針的間接引用,那么攻擊者可能會利用引發的異常發動 denial of service 攻擊,或使應用程序泄漏 debugging information,這些信息對于他們制定接下來的攻擊計劃是十分有價值的。
例 1:在下列代碼中,程序員確認變量 ptr 不是 NULL,并在接下來錯誤地進行間接引用。當在 if 指令中檢查時,如果 ptr 為 NULL ,則會發生 null dereference,從而引起 segmentation fault。
if (ptr == null) {
ptr->field = val;
...
}
NULL,從而間接引用一個 null 指針,并引發了 segmentation fault。
if (ptr == '\0') {
*ptr = val;
...
}
[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 476
[5] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.9