Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

File names containing particular characters can be troublesome and can cause unexpected behavior leading to potential vulnerabilities. If a program allows the user to specify a file name in the creation or renaming of a file, certain checks should be made to disallow the following characters and patterns:

  • Leading dashes - Leading dashes—Leading dashes can cause problems when programs are called with the file name as a parameter because the first character or characters of the file name might be interpreted as an option switch.
  • Control characters, such as newlines, carriage returns, and escape - Control escape—Control characters in a file name can cause unexpected results from shell scripts and in logging.
  • Spaces - Spaces Spaces—Spaces can cause problems with scripts and when double quotes aren't used to surround the file name.
  • Invalid character encodings - Character encodings—Character encodings can be a huge issue. (see See guideline MSC10-C. Character Encoding - UTF8 Related Issues.).
  • Any characters other than letters, numbers, and punctuation designated here as portable - Other portable—Other special characters are included in this recommendation because they are commonly used as separators and having them in a file name can cause unexpected and potentially insecure behavior.

...

Most of these characters or patterns are primarily a problem to scripts or automated parsing, but, because they are not commonly used, it is best to disallow their use to reduce potential problems. Interoperability concerns also exist because different operating systems handle file names of this sort in different ways.

Wiki Markup
As a result of the influence of MS-DOS, file names of the form {{xxxxxxxx.xxx}}, where x denotes an alphanumeric character, are generally supported by modern systems.  On some platforms, file names are case sensitive,; while on other platforms, they are case insensitive.  VU#439395 is an example of a vulnerability resulting from a failure to deal appropriately with case sensitivity issues \[[VU#439395|AA. Bibliography#VU439395]\].

...

This noncompliant code example is derived from guideline FIO30-C. Exclude user input from format strings, except that a newline is removed on the assumption that fgets() will include it.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

MSC09-C

medium

unlikely

medium

P4

L3

Automated Detection

...

Tool

Version

Checker

Description

Section

LDRA tool suite

...

Include Page
c:LDRA_V
c:LDRA_V

 

 

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

Related Guidelines

This rule appears in the C++ Secure Coding Standard as : MSC09-CPP. Character Encoding - Use Subset of ASCII for Safety.

Bibliography

Wiki Markup
\[[Kuhn 062006|AA. Bibliography#Kuhn 06]\] UTF-8 and Unicode FAQ for UNIX/Linux
\[[ISO/IEC 646-1991|AA. Bibliography#ISO/IEC 646-1991]\] ISO 7-bit coded character set for information interchange
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 5.2.1, "Character sets"
\[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "AJN Choice of Filenames and other External Identifiers"
\[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 3.2, "The character set and the corresponding encoding shall be documented," and Rule 4.1, "Only those escape sequences that are defined in the ISO C standard shall be used"
\[[MITRE 072007|AA. Bibliography#MITRE 07]\] [CWE ID 116|http://cwe.mitre.org/data/definitions/116.html], "Improper Encoding or Escaping of Output" 
\[[Wheeler 032003|AA. Bibliography#Wheeler03]\] 5.4 File Names
\[[VU#881872|AA. Bibliography#VU881872]\]

...