CWE-785: Use of Path Manipulation Function without Maximum-sized Buffer

Export to Word

Description

The product invokes a function for normalizing paths or file names, but it provides an output buffer that is smaller than the maximum possible size, such as PATH_MAX.

Extended Description

Passing an inadequately-sized output buffer to a path manipulation function can result in a buffer overflow. Such functions include realpath(), readlink(), PathAppend(), and others.


ThreatScore

Threat Mapped score: 1.5

Industry: Finiancial

Threat priority: P4 - Informational (Low)


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)

N/A


Attack TTPs

N/A

Modes of Introduction

Phase Note
Implementation N/A

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: In this example the function creates a directory named "output\<name>" in the current directory and returns a heap-allocated copy of its name.

Body: For most values of the current directory and the name parameter, this function will work properly. However, if the name parameter is particularly long, then the second call to PathAppend() could overflow the outputDirectoryName buffer, which is smaller than MAX_PATH bytes.

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); }

Notes

← Back to CWE list