Weakness ID: 704
Vulnerability Mapping: ALLOWED This CWE ID could be used to map to real-world vulnerabilities in limited situations requiring careful review (with careful review of mapping notes)Abstraction: 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.
Description
The product does not correctly convert an object, resource, or structure from one type to a different type.
Common Consequences
This table specifies different individual consequences
associated with the weakness. The Scope identifies the application security area that is
violated, while the Impact describes the negative technical impact that arises if an
adversary succeeds in exploiting this weakness. The Likelihood provides information about
how likely the specific consequence is expected to be seen relative to the other
consequences in the list. For example, there may be high likelihood that a weakness will be
exploited to achieve a certain impact, but a low likelihood that it will be exploited to
achieve a different impact.
| Impact | Details |
|---|---|
|
Other |
Scope: Other |
Relationships
This table shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition,
relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user
may want to explore.
Relevant to the view "Research Concepts" (View-1000)
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf |
|
664 | Improper Control of a Resource Through its Lifetime |
| ParentOf |
|
588 | Attempt to Access Child of a Non-structure Pointer |
| ParentOf |
|
681 | Incorrect Conversion between Numeric Types |
| ParentOf |
|
843 | Access of Resource Using Incompatible Type ('Type Confusion') |
| ParentOf |
|
1389 | Incorrect Parsing of Numbers with Different Radices |
Relevant to the view "Weaknesses for Simplified Mapping of Published Vulnerabilities" (View-1003)
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf |
|
1003 | Weaknesses for Simplified Mapping of Published Vulnerabilities |
| ParentOf |
|
681 | Incorrect Conversion between Numeric Types |
| ParentOf |
|
843 | Access of Resource Using Incompatible Type ('Type Confusion') |
Modes
Of Introduction
The different Modes of Introduction provide information
about how and when this
weakness may be introduced. The Phase identifies a point in the life cycle at which
introduction
may occur, while the Note provides a typical scenario related to introduction during the
given
phase.
| Phase | Note |
|---|---|
| Implementation |
Applicable Platforms
This listing shows possible areas for which the given
weakness could appear. These
may be for specific named Languages, Operating Systems, Architectures, Paradigms,
Technologies,
or a class of such platforms. The platform is listed along with how frequently the given
weakness appears for that instance.
| Languages |
C (Often Prevalent) C++ (Often Prevalent) Class: Not Language-Specific (Undetermined Prevalence) Class: Memory-Unsafe (Undetermined Prevalence) |
| Technologies |
Class: Not Technology-Specific (Undetermined Prevalence) |
Demonstrative Examples
Example 1
In this example, depending on the return value of accecssmainframe(), the variable amount can hold a negative value when it is returned. Because the function is declared to return an unsigned value, amount will be implicitly cast to an unsigned number.
(bad code)
Example Language: C
unsigned int readdata () {
int amount = 0;
...
amount = accessmainframe();
...
return amount;
}
If the return value of accessmainframe() is -1, then the return value of readdata() will be 4,294,967,295 on a system that uses 32-bit integers.
Example 2
The following code uses a union to support the representation of different types of messages. It formats messages differently, depending on their type.
(bad code)
Example Language: C
#define NAME_TYPE 1
#define ID_TYPE 2
struct MessageBuffer
{
int msgType;
union {
char *name;
int nameID;
};
};
int main (int argc, char **argv) {
struct MessageBuffer buf;
char *defaultMessage = "Hello World";
buf.msgType = NAME_TYPE;
buf.name = defaultMessage;
printf("Pointer of buf.name is %p\n", buf.name);
/* This particular value for nameID is used to make the code architecture-independent. If coming from untrusted input, it could be any value. */
buf.nameID = (int)(defaultMessage + 1);
printf("Pointer of buf.name is now %p\n", buf.name);
if (buf.msgType == NAME_TYPE) {
printf("Message: %s\n", buf.name);
}
else {
printf("Message: Use ID %d\n", buf.nameID);
}
}
The code intends to process the message as a NAME_TYPE, and sets the default message to "Hello World." However, since both buf.name and buf.nameID are part of the same union, they can act as aliases for the same memory location, depending on memory layout after compilation.
As a result, modification of buf.nameID - an int - can effectively modify the pointer that is stored in buf.name - a string.
Execution of the program might generate output such as:
Pointer of name is 10830
Pointer of name is now 10831
Message: ello World
Notice how the pointer for buf.name was changed, even though buf.name was not explicitly modified.
In this case, the first "H" character of the message is omitted. However, if an attacker is able to fully control the value of buf.nameID, then buf.name could contain an arbitrary pointer, leading to out-of-bounds reads or writes.
Selected Observed
Examples
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 |
|---|---|
|
Chain: in a web browser, an unsigned 64-bit integer is forcibly cast to a 32-bit integer (CWE-681) and potentially leading to an integer overflow (CWE-190). If an integer overflow occurs, this can cause heap memory corruption (CWE-122) |
|
|
Chain: data visualization program written in PHP uses the "!=" operator instead of the type-strict "!==" operator (CWE-480) when validating hash values, potentially leading to an incorrect type conversion (CWE-704) |
Weakness Ordinalities
| Ordinality | Description |
|---|---|
|
Primary |
(where the weakness exists independent of other weaknesses) |
Detection
Methods
| Method | Details |
|---|---|
|
Fuzzing |
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues. Effectiveness: High |
Memberships
This MemberOf Relationships table shows additional CWE Categories and Views that
reference this weakness as a member. This information is often useful in understanding where a
weakness fits within the context of external information sources.
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | 737 | CERT C Secure Coding Standard (2008) Chapter 4 - Expressions (EXP) | |
| MemberOf | 741 | CERT C Secure Coding Standard (2008) Chapter 8 - Characters and Strings (STR) | |
| MemberOf | 747 | CERT C Secure Coding Standard (2008) Chapter 14 - Miscellaneous (MSC) | |
| MemberOf | 875 | CERT C++ Secure Coding Section 07 - Characters and Strings (STR) | |
| MemberOf | 883 | CERT C++ Secure Coding Section 49 - Miscellaneous (MSC) | |
| MemberOf | 998 | SFP Secondary Cluster: Glitch in Computation | |
| MemberOf | 1129 | CISQ Quality Measures (2016) - Reliability | |
| MemberOf | 1157 | SEI CERT C Coding Standard - Guidelines 03. Expressions (EXP) | |
| MemberOf | 1158 | SEI CERT C Coding Standard - Guidelines 04. Integers (INT) | |
| MemberOf | 1161 | SEI CERT C Coding Standard - Guidelines 07. Characters and Strings (STR) | |
| MemberOf | 1306 | CISQ Quality Measures - Reliability | |
| MemberOf | 1340 | CISQ Data Protection Measures | |
| MemberOf | 1416 | Comprehensive Categorization: Resource Lifecycle Management |
Vulnerability Mapping Notes
| Usage |
ALLOWED-WITH-REVIEW
(this CWE ID could be used to map to real-world vulnerabilities in limited situations requiring careful review) |
| Reason | Abstraction |
|
Rationale |
This CWE entry is a Class and might have Base-level children that would be more appropriate |
|
Comments |
Examine children of this entry to see if there is a better fit |
Taxonomy
Mappings
| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| CERT C Secure Coding | EXP05-C | Do not cast away a const qualification | |
| CERT C Secure Coding | EXP39-C | CWE More Abstract | Do not access a variable through a pointer of an incompatible type |
| CERT C Secure Coding | INT31-C | CWE More Abstract | Ensure that integer conversions do not result in lost or misinterpreted data |
| CERT C Secure Coding | INT36-C | CWE More Abstract | Converting a pointer to integer or integer to pointer |
| CERT C Secure Coding | STR34-C | CWE More Abstract | Cast characters to unsigned types before converting to larger integer sizes |
| CERT C Secure Coding | STR37-C | CWE More Abstract | Arguments to character handling functions must be representable as an unsigned char |
| Software Fault Patterns | SFP1 | Glitch in computation | |
| OMG ASCRM | ASCRM-CWE-704 |
References
Content
History
Submissions |
||
|---|---|---|
| Submission Date | Submitter | Organization |
|
2008-09-09
(CWE 1.0, 2008-09-09) |
CWE Content Team | MITRE |
| Note: this date reflects when the entry was first published. Draft versions of this entry were provided to members of the CWE community and modified between Draft 9 and 1.0. | ||
Modifications |
||
| Modification Date | Modifier | Organization |
|
2025-12-11
(CWE 4.19, 2025-12-11) |
CWE Content Team | MITRE |
| updated Applicable_Platforms, Weakness_Ordinalities | ||
|
2024-02-29
(CWE 4.14, 2024-02-29) |
CWE Content Team | MITRE |
| updated Observed_Examples | ||
|
2023-10-26
(CWE 4.13, 2023-10-26) |
CWE Content Team | MITRE |
| updated Demonstrative_Examples, Observed_Examples | ||
|
2023-06-29
(CWE 4.12, 2023-06-29) |
CWE Content Team | MITRE |
| updated Mapping_Notes | ||
|
2023-04-27
(CWE 4.11, 2023-04-27) |
CWE Content Team | MITRE |
| updated Detection_Factors, Relationships, Time_of_Introduction | ||
|
2023-01-31
(CWE 4.10, 2023-01-31) |
CWE Content Team | MITRE |
| updated Description | ||
|
2022-10-13
(CWE 4.9, 2022-10-13) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2020-12-10
(CWE 4.3, 2020-12-10) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2020-08-20
(CWE 4.2, 2020-08-20) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2020-02-24
(CWE 4.0, 2020-02-24) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2019-06-20
(CWE 3.3, 2019-06-20) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2019-01-03
(CWE 3.2, 2019-01-03) |
CWE Content Team | MITRE |
| updated References, Relationships, Taxonomy_Mappings | ||
|
2017-11-08
(CWE 3.0, 2017-11-08) |
CWE Content Team | MITRE |
| updated Applicable_Platforms, Taxonomy_Mappings | ||
|
2017-01-19
(CWE 2.10, 2017-01-19) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2015-12-07
(CWE 2.9, 2015-12-07) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2014-07-30
(CWE 2.8, 2014-07-31) |
CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
|
2012-05-11
(CWE 2.2, 2012-05-15) |
CWE Content Team | MITRE |
| updated Relationships | ||
|
2011-09-13
(CWE 2.1, 2011-09-13) |
CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
|
2011-06-01
(CWE 1.13, 2011-06-01) |
CWE Content Team | MITRE |
| updated Common_Consequences, Relationships | ||
|
2009-05-27
(CWE 1.4, 2009-05-27) |
CWE Content Team | MITRE |
| updated Description | ||
|
2008-11-24
(CWE 1.1, 2008-11-25) |
CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
|
2008-07-01
(CWE 1.0, 2008-09-09) |
Eric Dalci | Cigital |
| updated Time_of_Introduction | ||
