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

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.

Submission Date :

July 27, 2009, midnight

Modification Date :

2023-06-29 00:00:00+00:00

Organization :

MITRE
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.

Example Vulnerable Codes

Example - 1

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


return null;
return null;

return null;

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

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.

Related Weaknesses

This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.

Visit http://cwe.mitre.org/ for more details.

© cvefeed.io
Latest DB Update: Nov. 21, 2024 23:11