This vulnerability occurs when a program attempts to shift an integer's bits by an invalid amount—either a negative number or a value equal to or greater than the integer's bit width (e.g., shifting a 32-bit integer by 32 or more places). This leads to unpredictable and platform-dependent results.
Shifting bits by a negative count is considered undefined behavior in languages like C and C++. Compilers and interpreters typically don't validate this at runtime, leaving the actual operation to be handled by the underlying hardware. Different CPU architectures may produce varying results—such as shifting in the opposite direction, yielding zero, or even causing a crash—which breaks code portability and introduces subtle bugs. Similarly, an overshift (shifting beyond the bit width) also produces undefined or implementation-defined results. Some languages or compilers might mask the shift count, wrap the value, or return zero, but you cannot rely on consistent behavior. This ambiguity makes the code's outcome architecture- and compiler-dependent, creating security risks when the shifted value is used for calculations, memory offsets, or access controls.
Impact: DoS: Crash, Exit, or Restart
unsigned int r = 1 << -5;
int choose_bit(int reg_bit, int bit_number_from_elsewhere) {
cint choose_bit(int reg_bit, int bit_number_from_elsewhere) {
c