File:cipher/elgamal.c
function : generate_using_x
Line of error:387
libgcrypt version 1.5.4 code:
p = _gcry_generate_elg_prime ( 0, nbits, qbits, g, ret_factors );
mpi_sub_ui (p_min1, p, 1);
-> Here p is being allocated value by function '_gcry_generate_elg_prime'
which has a very high probability of returning value NULL. So 'p' which may have
a NULL value is being dereferenced ,a line below, at line 387 during call
'mpi_sub_ui (p_min1, p, 1);'
-> So an assert (gcry_assert) can be used to check 'p' for not being 'NULL' .
Modified Code:
p = _gcry_generate_elg_prime ( 0, nbits, qbits, g, ret_factors );
gcry_assert (p); mpi_sub_ui (p_min1, p, 1);
I am adding a patch for the above mentioned bug's resolution.