aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-09-11 15:06:16 +0000
committerWerner Koch <[email protected]>2014-09-11 15:06:22 +0000
commitcd53cdbc3774fb193bdebcdc5d7019ddebc16dbc (patch)
treeff7a3058a181f54dfb6aa534237e7800b47ee280
parentmpi: Suppress set-but-unused-variables warnings. (diff)
downloadgnupg-cd53cdbc3774fb193bdebcdc5d7019ddebc16dbc.tar.gz
gnupg-cd53cdbc3774fb193bdebcdc5d7019ddebc16dbc.zip
mpi: Improve mpi_invm to detect bad input.
* mpi/mpi-inv.c (mpi_invm): Return 0 for bad input. -- Without this patch the function may enter an endless loop. This is a backport from libgcrypt. GnuPG-bug-id: 1713
-rw-r--r--mpi/mpi-inv.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/mpi/mpi-inv.c b/mpi/mpi-inv.c
index b76263047..361c57ea4 100644
--- a/mpi/mpi-inv.c
+++ b/mpi/mpi-inv.c
@@ -165,6 +165,11 @@ mpi_invm( MPI x, MPI a, MPI n )
int sign;
int odd ;
+ if (!mpi_cmp_ui (a, 0))
+ return 0; /* Inverse does not exists. */
+ if (!mpi_cmp_ui (n, 1))
+ return 0; /* Inverse does not exists. */
+
u = mpi_copy(a);
v = mpi_copy(n);