From 6d0f7e48898b51076bd4c844855ab9b1da7edd36 Mon Sep 17 00:00:00 2001 From: Florin Chirica Date: Tue, 27 Jun 2023 19:43:46 +0300 Subject: [PATCH] Division by 0 catching. (#1) * Division by 0 catching. * Use mpz_sgn. --- src/bqfc.c | 4 ++++ src/proof_common.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/bqfc.c b/src/bqfc.c index 7994192d..54fa8d75 100644 --- a/src/bqfc.c +++ b/src/bqfc.c @@ -68,6 +68,10 @@ int bqfc_decompr(mpz_t out_a, mpz_t out_b, const mpz_t D, const struct qfb_c *c) mpz_set(t, c->t); } + if (mpz_sgn(c->a) == 0) { + ret = -1; + goto out; + } mpz_gcdext(tmp, t_inv, NULL, t, c->a); if (mpz_cmp_ui(tmp, 1)) { ret = -1; diff --git a/src/proof_common.h b/src/proof_common.h index a1c7087a..0054e170 100644 --- a/src/proof_common.h +++ b/src/proof_common.h @@ -65,6 +65,9 @@ form DeserializeForm(const integer &D, const uint8_t *bytes, size_t size) integer FastPow(uint64_t a, uint64_t b, integer& c) { integer res, a1 = integer(a); + if (mpz_sgn(c.impl) == 0) { + throw std::runtime_error("Division by 0"); + } mpz_powm_ui(res.impl, a1.impl, b, c.impl); return res; }