diff -urN strongswan-4.2.6/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c strongswan-4.2.6-patched/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c --- strongswan-4.2.6/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c 2008-06-20 22:17:15.000000000 +0200 +++ strongswan-4.2.6-patched/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c 2008-09-22 09:33:40.000000000 +0200 @@ -343,7 +343,7 @@ * Generator value. */ mpz_t g; - + /** * My private value. */ @@ -353,7 +353,7 @@ * My public value. */ mpz_t ya; - + /** * Other public value. */ @@ -373,7 +373,7 @@ * Modulus length. */ size_t p_len; - + /** * True if shared secret is computed and stored in my_public_value. */ @@ -395,7 +395,7 @@ /* check public value: * 1. 0 or 1 is invalid as 0^a = 0 and 1^a = 1 * 2. a public value larger or equal the modulus is invalid */ - if (mpz_cmp_ui(this->yb, 1) > 0 || + if (mpz_cmp_ui(this->yb, 1) > 0 && mpz_cmp(this->yb, p_min_1) < 0) { #ifdef EXTENDED_DH_TEST @@ -440,7 +440,11 @@ return FAILED; } value->len = this->p_len; - value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb); + value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb); + if (value->ptr == NULL) + { + return FAILED; + } return SUCCESS; } @@ -451,6 +455,10 @@ { value->len = this->p_len; value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->ya); + if (value->ptr == NULL) + { + value->len = 0; + } } /** @@ -463,7 +471,11 @@ return FAILED; } secret->len = this->p_len; - secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz); + secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz); + if (secret->ptr == NULL) + { + return FAILED; + } return SUCCESS; } diff -urN strongswan-4.2.6/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c strongswan-4.2.6-patched/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c --- strongswan-4.2.6/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c 2008-06-20 22:17:15.000000000 +0200 +++ strongswan-4.2.6-patched/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c 2008-09-22 09:33:29.000000000 +0200 @@ -191,6 +191,10 @@ decrypted.len = this->k; decrypted.ptr = mpz_export(NULL, NULL, 1, decrypted.len, 1, 0, t1); + if (decrypted.ptr == NULL) + { + decrypted.len = 0; + } mpz_clear_randomized(t1); mpz_clear_randomized(t2); diff -urN strongswan-4.2.6/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c strongswan-4.2.6-patched/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c --- strongswan-4.2.6/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c 2008-06-20 22:17:15.000000000 +0200 +++ strongswan-4.2.6-patched/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c 2008-09-22 09:33:29.000000000 +0200 @@ -93,11 +93,15 @@ mpz_powm(c, m, this->e, this->n); - encrypted.len = this->k; - encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c); + encrypted.len = this->k; + encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c); + if (encrypted.ptr == NULL) + { + encrypted.len = 0; + } mpz_clear(c); - mpz_clear(m); + mpz_clear(m); return encrypted; } diff -urN strongswan-4.2.6/src/openac/openac.c strongswan-4.2.6-patched/src/openac/openac.c --- strongswan-4.2.6/src/openac/openac.c 2008-06-20 22:17:17.000000000 +0200 +++ strongswan-4.2.6-patched/src/openac/openac.c 2008-09-22 09:33:29.000000000 +0200 @@ -103,6 +103,10 @@ chunk.len = 1 + mpz_sizeinbase(number, 2)/BITS_PER_BYTE; chunk.ptr = mpz_export(NULL, NULL, 1, chunk.len, 1, 0, number); + if (chunk.ptr == NULL) + { + chunk.len = 0; + } return chunk; }