Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflows when adding/subtracting user-provided lengths #86

Open
albertvaka opened this issue Apr 6, 2024 · 0 comments
Open

Overflows when adding/subtracting user-provided lengths #86

albertvaka opened this issue Apr 6, 2024 · 0 comments

Comments

@albertvaka
Copy link
Contributor

albertvaka commented Apr 6, 2024

I wonder if there's a risk of out-of-bounds write when reading user-provided sizes and offsets and doing arithmetic operations with them. In network-facing libraries that deal with potential unsanitized input, I've often seen checks for overflow, eg:

int safe_subtract(int x, int y, int *result) {
    if (y > 0 && x < INT_MIN + y) {
        // Underflow would occur
        return 0;
    } else if (y < 0 && x > INT_MAX + y) {
        // Overflow would occur
        return 0;
    } else {
        // Safe to subtract
        *result = x - y;
        return 1;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant