Просмотр исходного кода

fix: potential undefined behavior in mbedtls_mpi_sub_abs()

https://github.com/Mbed-TLS/mbedtls/issues/6701
Wendal Chen 2 лет назад
Родитель
Сommit
467621a12d
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      components/mbedtls/library/bignum.c

+ 1 - 1
components/mbedtls/library/bignum.c

@@ -1237,7 +1237,7 @@ int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
     /* Set the high limbs of X to match A. Don't touch the lower limbs
      * because X might be aliased to B, and we must not overwrite the
      * significant digits of B. */
-    if( A->n > n )
+    if( A->n > n && A != X)
         memcpy( X->p + n, A->p + n, ( A->n - n ) * ciL );
     if( X->n > A->n )
         memset( X->p + A->n, 0, ( X->n - A->n ) * ciL );