<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            Unreleased Resource: Sockets

            ABSTRACT

            程序可能無法釋放某個套接字。

            EXPLANATION

            程序可能無法成功釋放某一個套接字。


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

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

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

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

            例 1:下面的方法絕不會關閉它所打開的套接字。在繁忙的環境中,這會導致 JVM 用盡它所有的套接字。


            private void echoSocket(String host, int port) throws UnknownHostException, SocketException, IOException
            {
            Socket sock = new Socket(host, port);
            BufferedReader reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));

            while ((String socketData = reader.readLine()) != null) {
            System.out.println(socketData);
            }
            }


            例 2:正常情況下,以下修復代碼會正常關閉套接字以及任何相關聯的數據流。但如果在讀取輸入或將數據輸出到屏幕時出現異常,則不會關閉套接字對象。如果這種情況經常出現,系統將會耗盡所有套接字,無法處理更多連接。


            private void echoSocket(String host, int port) throws UnknownHostException, SocketException, IOException
            {
            Socket sock = new Socket(host, port);
            BufferedReader reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));

            while ((String socketData = reader.readLine()) != null) {
            System.out.println(socketData);
            }
            sock.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.java.unreleased_resource_sockets

            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      亚洲欧美在线