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

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

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

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

            Memory Leak: Reallocation

            ABSTRACT

            該程序會調整分配的內存塊的大小。如果調整大小時失敗,初始塊將會泄漏。

            EXPLANATION

            Memory leak 的產生有兩個常見(有時候這兩個原因會同時發生作用)原因:

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

            — 不清楚由程序的哪一部分負責釋放內存。

            大多數 memory leak 會導致一個常規軟件可靠性問題,但如果攻擊者能夠蓄意觸發 memory leak,他就可能會通過引發程序崩潰來發起一個 denial of service 攻擊,或者是利用因內存低的情況 [1] 所引發的其他意外的程序行為。

            例 1:如果 realloc() 調用無法調整初始分配的大小,以下 C 函數會泄漏一塊分配的內存。


            char* getBlocks(int fd) {
            int amt;
            int request = BLOCK_SIZE;
            char* buf = (char*) malloc(BLOCK_SIZE + 1);
            if (!buf) {
            goto ERR;
            }
            amt = read(fd, buf, request);
            while ((amt % BLOCK_SIZE) != 0) {
            if (amt < request) {
            goto ERR;
            }
            request = request + BLOCK_SIZE;
            buf = realloc(buf, request);
            if (!buf) {
            goto ERR;
            }
            amt = read(fd, buf, request);
            }

            return buf;

            ERR:
            if (buf) {
            free(buf);
            }
            return NULL;
            }

            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 401

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


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

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

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

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

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

                      亚洲欧美在线