The product uses an unsigned primitive and performs a cast to a signed primitive, which can produce an unexpected value if the value of the unsigned primitive can not be represented using a signed primitive.
View on MITREAlthough less frequent an issue than signed-to-unsigned conversion, unsigned-to-signed conversion can be the perfect precursor to dangerous buffer underwrite conditions that allow attackers to move down the stack where they otherwise might not have access in a normal buffer overflow condition. Buffer underwrites occur frequently when large unsigned values are cast to signed values, and then used as indexes into a buffer or for pointer arithmetic.
Incorrect sign conversions generally lead to undefined behavior, and therefore crashes.
If a poor cast lead to a buffer overflow or similar condition, data integrity may be affected.
Improper signed-to-unsigned conversions without proper checking can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program's implicit security policy.
Choose a language which is not subject to these casting flaws.
Design object accessor functions to implicitly check values for valid sizes. Ensure that all functions which will be used as a size are checked previous to use as a size. If the language permits, throw exceptions rather than using in-band errors.
Error check the return values of all functions. Be aware of implicit casts made, and use unsigned variables for sizes if at all possible.
No detection method information available for this CWE.
No examples or observed CVEs available for this CWE.
No relationship information available for this CWE.
CWE-196: Unsigned to Signed Conversion Error is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product uses an unsigned primitive and performs a cast to a signed primitive, which can produce an unexpected value if the value of the unsigned primitive can not be represented using a signed primitive. Although less frequent an issue than signed-to-unsigned conversion, unsigned-to-signed conversion can be the perfect precursor to dangerous buffer underwrite conditions that allow attackers to move down the stack where they otherwise might not have access in a normal buffer overflow condition. Buffer underwrites occur frequently when large unsigned values are cast to signed values, and then used as indexes into a buffer or for pointer arithmetic.
If exploited, CWE-196 (Unsigned to Signed Conversion Error) it can compromise Availability, Integrity, Confidentiality and Access Control, leading to outcomes such as DoS: Crash, Exit, or Restart, Modify Memory, Execute Unauthorized Code or Commands and Bypass Protection Mechanism.
Recommended mitigations for CWE-196 include: Choose a language which is not subject to these casting flaws. Design object accessor functions to implicitly check values for valid sizes. Ensure that all functions which will be used as a size are checked previous to use as a size. If the language permits, throw exceptions rather than using in-band errors. Error check the return values of all functions. Be aware of implicit casts made, and use unsigned variables for sizes if at all possible.
CWE-196 commonly affects C and C++. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
A CWE (Common Weakness Enumeration) like CWE-196 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.