Skip to content

Commit

Permalink
Merge pull request #726 from pshipton/mpi
Browse files Browse the repository at this point in the history
Modify jdk.crypto.ec libsunec mpi.c to avoid writes to unallocated mem
  • Loading branch information
keithc-ca authored Nov 9, 2023
2 parents e43aa73 + e9695f5 commit 5324599
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
* Last Modified Date from the Original Code: Nov 2019
*********************************************************************** */

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
* ===========================================================================
*/

/* Arbitrary precision integer arithmetic library */

#include "mpi-priv.h"
Expand Down Expand Up @@ -1727,17 +1733,28 @@ int mp_cmp_mag(mp_int *a, mp_int *b)
*/
int mp_cmp_int(const mp_int *a, long z, int kmflag)
{
mp_int tmp;
int out;
mp_sign signz = z < 0 ? NEG : ZPOS;

ARGCHK(a != NULL, MP_EQ);

mp_init(&tmp, kmflag); mp_set_int(&tmp, z);
out = mp_cmp(a, &tmp);
mp_clear(&tmp);
if(SIGN(a) == signz) {
unsigned long v = labs(z);

return out;
if(USED(a) > 1)
return signz == ZPOS ? MP_GT : MP_LT;

if(DIGIT(a, 0) == v)
return MP_EQ;
if(DIGIT(a, 0) > v) {
return signz == ZPOS ? MP_GT : MP_LT;
} else {
return signz == ZPOS ? MP_LT : MP_GT;
}
} else if(SIGN(a) == ZPOS) {
return MP_GT;
} else {
return MP_LT;
}
} /* end mp_cmp_int() */

/* }}} */
Expand Down

0 comments on commit 5324599

Please sign in to comment.