Katalog CWE

CWE-196 · Słabość

Unsigned to Signed Conversion Error

Abstrakcja
Wariant
Status
Szkic
Ryzyko wykorzystania
średnie
Dodano
19 lipca 2006
Ostatnia zmiana
11 grudnia 2025

Podatności CVE z tą słabościąPełny wpis na cwe.mitre.org ↗

Opis

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.

Skutki

  • Availability

    DoS: Crash, Exit, or Restart

    Incorrect sign conversions generally lead to undefined behavior, and therefore crashes.

  • Integrity

    Modify Memory

    If a poor cast lead to a buffer overflow or similar condition, data integrity may be affected.

  • Integrity, Confidentiality, Availability, Access Control

    Execute Unauthorized Code or Commands; Bypass Protection Mechanism

    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.

Zapobieganie

  • Requirements

    Choose a language which is not subject to these casting flaws.

  • Architecture and Design

    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.

  • Implementation

    Error check the return values of all functions. Be aware of implicit casts made, and use unsigned variables for sizes if at all possible.

Słabość nadrzędna

Może też być

Kiedy powstaje

Dotyczy

C, C++

Źródła

  1. The Art of Software Security Assessment — Mark Dowd, John McDonald, Justin Schuh, Chapter 6, "Type Conversions", Page 223, Addison Wesley, 2006
  2. The CLASP Application Security Process — Secure Software, Inc., 2005

Wpis z katalogu CWE 4.20.