Skip to content

Potential integer overflow at src/libev/ev.c #552

Description

@samitistfobos-dev

Potential problem
In array_nextsize (src/libev/ev.c, 2249), the size of the allocated array is calculated using int operands. The expression elem * ncur may exceed the range of int for sufficiently large values of ncur, causing signed integer overflow.
The same multiplication is subsequently performed by ncur *= elem, so changing only the comparison would leave another potentially overflowing operation.

Possible solution
It is suggested to use a separate long variable for calculations involving the array size in bytes. The multiplication can then be performed as (long)elem * ncur, and subsequent rounding calculations can also use this wider type before converting the resulting element count back to int.
This prevents signed integer overflow in the byte-size calculations while preserving ncur as the number of array elements.

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

Author A. Burlakov.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions