Difference between revisions of "Often Misused: File System"

From OWASP
Jump to: navigation, search
(Related Attacks)
Line 1: Line 1:
 
{{Template:Fortify}}
 
{{Template:Fortify}}
 
 
{{Template:Vulnerability}}
 
{{Template:Vulnerability}}
  

Revision as of 09:47, 19 July 2006

This article includes content generously donated to OWASP by Fortify.JPG.

This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.


Abstract

Passing an inadequately-sized output buffer to a path manipulation function can result in a buffer overflow.

Description

Windows provides a large number of utility functions that manipulate buffers containing filenames. In most cases, the result is returned in a buffer that is passed in as input. (Usually the filename is modified in place.) Most functions require the buffer to be at least MAX_PATH bytes in length, but you should check the documentation for each function individually. If the buffer is not large enough to store the result of the manipulation, a buffer overflow can occur.

Examples

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

In this example the function creates a directory named "output\<name>" in the current directory and returns a heap-allocated copy of its 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 Threats

Related Attacks

Related Vulnerabilities

Buffer overflow

Related Countermeasures

Categories