logo

Database

Rust Arithmetic Integer Overflow

Description

This detector identifies potential integer overflow vulnerabilities in Rust applications using the Actix Web framework. Integer overflow occurs when arithmetic operations result in values that exceed the data type's maximum capacity, potentially leading to unexpected behavior, security bypasses, or denial of service attacks.

Weakness:

067 - Improper resource allocation

Category: Functionality Abuse

Detection Strategy

    Reports vulnerabilities only in Rust code that imports the actix_web library

    Scans execution blocks within the code for arithmetic operations that could cause integer overflow

    Flags code patterns where mathematical operations may exceed integer type limits without proper bounds checking

Vulnerable code example

use actix_web::{get, web, HttpResponse};

#[get("/price/{quantity}")]
async fn calculate_price(path: web::Path<u32>) -> HttpResponse {
    let quantity = path.into_inner();
    let unit_price: u32 = 100;
    
    // VULNERABLE: unchecked multiplication can overflow in release builds...

✅ Secure code example

use actix_web::{get, web, HttpResponse};

#[get("/price/{quantity}")]
async fn calculate_price(path: web::Path<u32>) -> HttpResponse {
    let quantity = path.into_inner();
    let unit_price: u32 = 100;
    
    // SAFE: checked_mul returns None on overflow instead of wrapping...