<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>

    Unreleased Resource: Streams

    ABSTRACT

    程序可能無法成功釋放某一項系統資源。

    EXPLANATION

    程序可能無法成功釋放某一項系統資源。

    資源泄露至少有兩種常見的原因:

    - 錯誤狀況及其他異常情況。

    - 未明確程序的哪一部份負責釋放資源。

    大部分 Unreleased Resource 問題只會導致一般的軟件可靠性問題,但如果攻擊者能夠故意觸發資源泄漏,該攻擊者就有可能通過耗盡資源池的方式發起 denial of service 攻擊。

    例 1:下面的方法絕不會關閉它所打開的文件句柄。類 StreamReader 中的 Finalize() 方法最終會調用 Close(),但是不能確定何時會調用 Finalize() 方法。事實上,無法確保 Finalize() 會被調用。因此,在繁忙的環境中,這可能會導致 VM 用盡它所有的文件句柄。


    private void processFile(string fName) {
    StreamWriter sw = new StreamWriter(fName);
    string line;
    while ((line = sr.ReadLine()) != null)
    processLine(line);
    }


    例2:在正常條件下,下面的代碼會執行一條數據庫查詢語句,處理數據庫返回的結果,并關閉已分配的 SqlConnection 對象。但是如果在執行 SQL 或者處理查詢結果時發生異常,那么 SqlConnection 對象不會被關閉。如果這種情況頻繁出現,數據庫將用完所有可用的指針,且不能再執行任何 SQL 查詢。


    ...
    SqlConnection conn = new SqlConnection(connString);
    SqlCommand cmd = new SqlCommand(queryString);
    cmd.Connection = conn;
    conn.Open();
    SqlDataReader rdr = cmd.ExecuteReader();
    HarvestResults(rdr);
    conn.Connection.Close();
    ...

    REFERENCES

    [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 404

    [5] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.9

    [6] Standards Mapping - SANS Top 25 2009 - (SANS 2009) Risky Resource Management - CWE ID 404


    Copyright 2013 Fortify Software - All rights reserved.
    (Generated from version 2013.1.1.0008 of the Fortify Secure Coding Rulepacks)
    desc.controlflow.dotnet.unreleased_resource

    97av