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

    Often Misused: File System(windows)

    ABSTRACT

    將一個長度不合適的輸出緩沖區傳遞到一個 path manipulation 函數,會導致 buffer overflow。

    EXPLANATION

    Windows 提供了大量的實用程序函數來處理包含文件名的緩沖區。在大多數情況下,結果會返回到一個作為輸入傳入的緩沖區中。(通常文件名會進行適當的修改。)大多數函數需要緩沖區至少為 MAX_PATH 字節的長度,但是您應該逐一檢查每一個函數的文檔。如果緩沖區大小不足以存儲處理的結果,那么就會發生 buffer overflow。

    例:


    char *createOutputDirectory(char *name) {
    char outputDirectoryName[128];
    if (getCurrentDirectory(128, outputDirectoryName) == 0) {
    return null;
    }
    if (!PathAppend(outputDirectoryName, "output")) {
    return null;
    }
    if (!PathAppend(outputDirectoryName, name)) {
    return null;
    }
    if (SHCreateDirectoryEx(NULL, outputDirectoryName, NULL)
    != ERROR_SUCCESS) {
    return null;
    }
    return StrDup(outputDirectoryName);
    }


    在這個例子中,函數在當前目錄中創建了名為“output\<name>”的目錄,并且返回了一個同樣名稱的堆分配副本。對于大多數當前目錄和名稱參數的值來說,該函數都能夠正常工作。但是,如果 name 參數特別長,那么第二個對 PathAppend() 的調用可能會溢出 outputDirectoryName 緩沖區,因為該緩沖區比 MAX_PATH 字節小。

    REFERENCES

    [1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A5 Buffer Overflow

    [2] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3590.1 CAT I

    [3] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3590.1 CAT I

    [4] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 249, CWE ID 560

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

    [6] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.2

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


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

    97av