Impact | Details |
---|---|
Read Memory |
Scope: Confidentiality
Format string problems allow for information disclosure which can severely simplify exploitation of the program.
|
Modify Memory; Execute Unauthorized Code or Commands |
Scope: Integrity, Confidentiality, Availability
Format string problems can result in the execution of arbitrary code, buffer overflows, denial of service, or incorrect data representation.
|
Phase(s) | Mitigation |
---|---|
Requirements |
Choose a language that is not subject to this flaw.
|
Implementation |
|
Build and Compilation |
Run compilers and linkers with high warning levels, since they may detect incorrect usage.
|
Nature | Type | ID | Name |
---|---|---|---|
ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 668 | Exposure of Resource to Wrong Sphere |
CanPrecede | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 123 | Write-what-where Condition |
Nature | Type | ID | Name |
---|---|---|---|
MemberOf | Category Category - a CWE entry that contains a set of other entries that share a common characteristic. | 133 | String Errors |
Nature | Type | ID | Name |
---|---|---|---|
ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 668 | Exposure of Resource to Wrong Sphere |
Nature | Type | ID | Name |
---|---|---|---|
ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 20 | Improper Input Validation |
Phase | Note |
---|---|
Implementation | The programmer rarely intends for a format string to be externally-controlled at all. This weakness is frequently introduced in code that constructs log messages, where a constant format string is omitted. |
Implementation | In cases such as localization and internationalization, the language-specific message repositories could be an avenue for exploitation, but the format string issue would be resultant, since attacker control of those repositories would also allow modification of message length, format, and content. |
C (Often Prevalent)
C++ (Often Prevalent)
Perl (Rarely Prevalent)
Example 1
The following program prints a string provided as an argument.
The example is exploitable, because of the call to printf() in the printWrapper() function. Note: The stack buffer was added to make exploitation more simple.
Example 2
The following code copies a command line argument into a buffer using snprintf().
This code allows an attacker to view the contents of the stack and write to the stack using a command line argument containing a sequence of formatting directives. The attacker can read from the stack by providing more formatting directives, such as %x, than the function takes as arguments to be formatted. (In this example, the function takes no arguments to be formatted.) By using the %n formatting directive, the attacker can write to the stack, causing snprintf() to write the number of bytes output thus far to the specified argument (rather than reading a value from the argument, which is the intended behavior). A sophisticated version of this attack will use four staggered writes to completely control the value of a pointer on the stack.
Example 3
Certain implementations make more advanced attacks even easier by providing format directives that control the location in memory to read from or write to. An example of these directives is shown in the following code, written for glibc:
This code produces the following output: 5 9 5 5 It is also possible to use half-writes (%hn) to accurately control arbitrary DWORDS in memory, which greatly reduces the complexity needed to execute an attack that would otherwise require four staggered writes, such as the one mentioned in a separate example.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
Reference | Description |
---|---|
format string in Perl program
|
|
format string in bad call to syslog function
|
|
format string in bad call to syslog function
|
|
format strings in NNTP server responses
|
|
Format string vulnerability exploited by triggering errors or warnings, as demonstrated via format string specifiers in a .bmp filename.
|
|
Chain: untrusted search path enabling resultant format string by loading malicious internationalization messages
|
Ordinality | Description |
---|---|
Primary
|
(where the weakness exists independent of other weaknesses)
|
Method | Details |
---|---|
Automated Static Analysis |
This weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives.
|
Black Box |
Since format strings often occur in rarely-occurring erroneous conditions (e.g. for error message logging), they can be difficult to detect using black box methods. It is highly likely that many latent issues exist in executables that do not have associated source code (or equivalent source.
Effectiveness: Limited |
Automated Static Analysis - Binary or Bytecode |
According to SOAR [REF-1479], the following detection techniques may be useful: Highly cost effective:
Cost effective for partial coverage:
Effectiveness: High |
Manual Static Analysis - Binary or Bytecode |
According to SOAR [REF-1479], the following detection techniques may be useful: Cost effective for partial coverage:
Effectiveness: SOAR Partial |
Dynamic Analysis with Automated Results Interpretation |
According to SOAR [REF-1479], the following detection techniques may be useful: Cost effective for partial coverage:
Effectiveness: SOAR Partial |
Dynamic Analysis with Manual Results Interpretation |
According to SOAR [REF-1479], the following detection techniques may be useful: Cost effective for partial coverage:
Effectiveness: SOAR Partial |
Manual Static Analysis - Source Code |
According to SOAR [REF-1479], the following detection techniques may be useful: Highly cost effective:
Cost effective for partial coverage:
Effectiveness: High |
Automated Static Analysis - Source Code |
According to SOAR [REF-1479], the following detection techniques may be useful: Highly cost effective:
Cost effective for partial coverage:
Effectiveness: High |
Architecture or Design Review |
According to SOAR [REF-1479], the following detection techniques may be useful: Highly cost effective:
Cost effective for partial coverage:
Effectiveness: High |
Nature | Type | ID | Name |
---|---|---|---|
MemberOf | ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). | 635 | Weaknesses Originally Used by NVD from 2008 to 2016 |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 726 | OWASP Top Ten 2004 Category A5 - Buffer Overflows |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 743 | CERT C Secure Coding Standard (2008) Chapter 10 - Input Output (FIO) |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 808 | 2010 Top 25 - Weaknesses On the Cusp |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 845 | The CERT Oracle Secure Coding Standard for Java (2011) Chapter 2 - Input Validation and Data Sanitization (IDS) |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 865 | 2011 Top 25 - Risky Resource Management |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 877 | CERT C++ Secure Coding Section 09 - Input Output (FIO) |
MemberOf | ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). | 884 | CWE Cross-section |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 990 | SFP Secondary Cluster: Tainted Input to Command |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1131 | CISQ Quality Measures (2016) - Security |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1134 | SEI CERT Oracle Secure Coding Standard for Java - Guidelines 00. Input Validation and Data Sanitization (IDS) |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1163 | SEI CERT C Coding Standard - Guidelines 09. Input Output (FIO) |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1179 | SEI CERT Perl Coding Standard - Guidelines 01. Input Validation and Data Sanitization (IDS) |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1308 | CISQ Quality Measures - Security |
MemberOf | ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). | 1340 | CISQ Data Protection Measures |
MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1399 | Comprehensive Categorization: Memory Safety |
Rationale
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.Comments
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.Applicable Platform
This weakness is possible in any programming language that support format strings.
Research Gap
Other
In some circumstances, such as internationalization, the set of format strings is externally controlled by design. If the source of these format strings is trusted (e.g. only contained in library files that are only modifiable by the system administrator), then the external control might not itself pose a vulnerability.
While Format String vulnerabilities typically fall under the Buffer Overflow category, technically they are not overflowed buffers. The Format String vulnerability is fairly new (circa 1999) and stems from the fact that there is no realistic way for a function that takes a variable number of arguments to determine just how many arguments were passed in. The most common functions that take a variable number of arguments, including C-runtime functions, are the printf() family of calls. The Format String problem appears in a number of ways. A *printf() call without a format specifier is dangerous and can be exploited. For example, printf(input); is exploitable, while printf(y, input); is not exploitable in that context. The result of the first call, used incorrectly, allows for an attacker to be able to peek at stack memory since the input string will be used as the format specifier. The attacker can stuff the input string with format specifiers and begin reading stack values, since the remaining parameters will be pulled from the stack. Worst case, this improper use may give away enough control to allow an arbitrary value (or values in the case of an exploit program) to be written into the memory of the running program.
Frequently targeted entities are file names, process names, identifiers.
Format string problems are a classic C/C++ issue that are now rare due to the ease of discovery. One main reason format string vulnerabilities can be exploited is due to the %n operator. The %n operator will write the number of characters, which have been printed by the format string therefore far, to the memory pointed to by its argument. Through skilled creation of a format string, a malicious user may use values on the stack to create a write-what-where condition. Once this is achieved, they can execute arbitrary code. Other operators can be used as well; for example, a %9999s operator could also trigger a buffer overflow, or when used in file-formatting functions like fprintf, it can generate a much larger output than intended.
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
PLOVER | Format string vulnerability | ||
7 Pernicious Kingdoms | Format String | ||
CLASP | Format string problem | ||
CERT C Secure Coding | FIO30-C | Exact | Exclude user input from format strings |
CERT C Secure Coding | FIO47-C | CWE More Specific | Use valid format strings |
OWASP Top Ten 2004 | A1 | CWE More Specific | Unvalidated Input |
WASC | 6 | Format String | |
The CERT Oracle Secure Coding Standard for Java (2011) | IDS06-J | Exclude user input from format strings | |
SEI CERT Perl Coding Standard | IDS30-PL | Exact | Exclude user input from format strings |
Software Fault Patterns | SFP24 | Tainted input to command | |
OMG ASCSM | ASCSM-CWE-134 |
Submissions | |||
---|---|---|---|
Submission Date | Submitter | Organization | |
2006年07月19日
(CWE Draft 3, 2006年07月19日) |
PLOVER | ||
Modifications | |||
Modification Date | Modifier | Organization | |
2025年09月09日
(CWE 4.18, 2025年09月09日) |
CWE Content Team | MITRE | |
updated Detection_Factors, Functional_Areas, References | |||
2025年04月03日
(CWE 4.17, 2025年04月03日) |
CWE Content Team | MITRE | |
updated Common_Consequences, Demonstrative_Examples, Description, Diagram, Other_Notes | |||
2023年06月29日 | CWE Content Team | MITRE | |
updated Mapping_Notes | |||
2023年04月27日 | CWE Content Team | MITRE | |
updated References, Relationships | |||
2023年01月31日 | CWE Content Team | MITRE | |
updated Description | |||
2021年03月15日 | CWE Content Team | MITRE | |
updated Potential_Mitigations, Relationships | |||
2020年12月10日 | CWE Content Team | MITRE | |
updated Common_Consequences, Relationships | |||
2020年08月20日 | CWE Content Team | MITRE | |
updated Relationships | |||
2020年02月24日 | CWE Content Team | MITRE | |
updated Detection_Factors, Relationships | |||
2019年09月19日 | CWE Content Team | MITRE | |
updated Relationships | |||
2019年06月20日 | CWE Content Team | MITRE | |
updated Relationships | |||
2019年01月03日 | CWE Content Team | MITRE | |
updated References, Relationships, Taxonomy_Mappings | |||
2018年03月27日 | CWE Content Team | MITRE | |
updated References | |||
2017年11月08日 | CWE Content Team | MITRE | |
updated Applicable_Platforms, Causal_Nature, Functional_Areas, Likelihood_of_Exploit, Other_Notes, References, Relationships, Taxonomy_Mappings, White_Box_Definitions | |||
2015年12月07日 | CWE Content Team | MITRE | |
updated Description, Modes_of_Introduction, Name, Relationships | |||
2014年07月30日 | CWE Content Team | MITRE | |
updated Demonstrative_Examples, Detection_Factors, Relationships, Taxonomy_Mappings | |||
2012年05月11日 | CWE Content Team | MITRE | |
updated Observed_Examples, References, Related_Attack_Patterns, Relationships, Taxonomy_Mappings | |||
2011年09月13日 | CWE Content Team | MITRE | |
updated Potential_Mitigations, References, Relationships, Taxonomy_Mappings | |||
2011年06月27日 | CWE Content Team | MITRE | |
updated Modes_of_Introduction, Relationships | |||
2011年06月01日 | CWE Content Team | MITRE | |
updated Common_Consequences, Relationships, Taxonomy_Mappings | |||
2010年02月16日 | CWE Content Team | MITRE | |
updated Detection_Factors, References, Relationships, Taxonomy_Mappings | |||
2009年07月27日 | CWE Content Team | MITRE | |
updated White_Box_Definitions | |||
2009年07月17日 | KDM Analytics | ||
Improved the White_Box_Definition | |||
2009年05月27日 | CWE Content Team | MITRE | |
updated Demonstrative_Examples | |||
2009年03月10日 | CWE Content Team | MITRE | |
updated Relationships | |||
2008年11月24日 | CWE Content Team | MITRE | |
updated Relationships, Taxonomy_Mappings | |||
2008年09月08日 | CWE Content Team | MITRE | |
updated Applicable_Platforms, Common_Consequences, Detection_Factors, Modes_of_Introduction, Relationships, Other_Notes, Research_Gaps, Taxonomy_Mappings, Weakness_Ordinalities | |||
2008年08月01日 | KDM Analytics | ||
added/updated white box definitions | |||
Previous Entry Names | |||
Change Date | Previous Entry Name | ||
2015年12月07日 | Uncontrolled Format String |
Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2025, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.