Skip to content

Commit f61bbf8

Browse files
Andy Polyakovmattcaswell
authored andcommitted
bn/bn_gf2m.c: avoid infinite loop wich malformed ECParamters.
CVE-2015-1788 Reviewed-by: Matt Caswell <matt@openssl.org> (cherry picked from commit 4924b37)
1 parent 1f31458 commit f61bbf8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crypto/bn/bn_gf2m.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,10 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
694694
}
695695
# else
696696
{
697-
int i, ubits = BN_num_bits(u), vbits = BN_num_bits(v), /* v is copy
698-
* of p */
699-
top = p->top;
697+
int i;
698+
int ubits = BN_num_bits(u);
699+
int vbits = BN_num_bits(v); /* v is copy of p */
700+
int top = p->top;
700701
BN_ULONG *udp, *bdp, *vdp, *cdp;
701702

702703
bn_wexpand(u, top);
@@ -740,8 +741,12 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
740741
ubits--;
741742
}
742743

743-
if (ubits <= BN_BITS2 && udp[0] == 1)
744-
break;
744+
if (ubits <= BN_BITS2) {
745+
if (udp[0] == 0) /* poly was reducible */
746+
goto err;
747+
if (udp[0] == 1)
748+
break;
749+
}
745750

746751
if (ubits < vbits) {
747752
i = ubits;

0 commit comments

Comments
 (0)