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

Backport 2.28: Fix undefined behavior in bignum: NULL+0 and -most-negative-sint #6618

Commits on Nov 17, 2022

  1. Document mbedtls_mpi_uint and mbedtls_mpi_sint

    Since they're part of the public API (even if only through a few functions),
    they should be documented.
    
    I deliberately skipped documenting how to configure the size of the type.
    Right now, MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 have no Doxygen
    documentation, so it's ambiguous whether they're part of the public API.
    Resolving this ambiguity is out of scope of my current work.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Nov 17, 2022
    Configuration menu
    Copy the full SHA
    cab02f6 View commit details
    Browse the repository at this point in the history
  2. Fix NULL+0 in addition 0 + 0

    Fix undefined behavior (typically harmless in practice) of
    mbedtls_mpi_add_mpi(), mbedtls_mpi_add_abs() and mbedtls_mpi_add_int() when
    both operands are 0 and the left operand is represented with 0 limbs.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Nov 17, 2022
    Configuration menu
    Copy the full SHA
    103cf59 View commit details
    Browse the repository at this point in the history
  3. Fix undefined behavior with the most negative mbedtls_mpi_sint

    When x is the most negative value of a two's complement type,
    `(unsigned_type)(-x)` has undefined behavior, whereas `-(unsigned_type)x`
    has well-defined behavior and does what was intended.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Nov 17, 2022
    Configuration menu
    Copy the full SHA
    de1629a View commit details
    Browse the repository at this point in the history
  4. Express abs(z) in a way that satisfies GCC and MSVC

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Nov 17, 2022
    Configuration menu
    Copy the full SHA
    ae7cbd7 View commit details
    Browse the repository at this point in the history