1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-09 23:33:46 -05:00

Move null pointer checks to before FROMFIELD.

This fixes an oversight in commit 0fc2d3b45: if a key creation
function returns a null 'ssh_key *', then adjusting the pointer's
address using FROMFIELD is a mistake, both in technical C terms
(undefined behaviour) and practically speaking because it will foil
the subsequent check against NULL. Instead, if we're going to check a
pointer against NULL, we must do it _before_ applying this kind of
address-adjusting type conversion.
This commit is contained in:
Simon Tatham
2018-05-31 18:32:09 +01:00
parent 2cf07bb8fe
commit 619f6722d8
3 changed files with 40 additions and 23 deletions

View File

@ -295,6 +295,7 @@ static ssh_key *dss_createkey(const ssh_keyalg *self,
const void *pub_blob, int pub_len,
const void *priv_blob, int priv_len)
{
ssh_key *sshk;
struct dss_key *dss;
const char *pb = (const char *) priv_blob;
const char *hash;
@ -303,10 +304,11 @@ static ssh_key *dss_createkey(const ssh_keyalg *self,
unsigned char digest[20];
Bignum ytest;
dss = FROMFIELD(dss_newkey(self, pub_blob, pub_len),
struct dss_key, sshk);
if (!dss)
sshk = dss_newkey(self, pub_blob, pub_len);
if (!sshk)
return NULL;
dss = FROMFIELD(sshk, struct dss_key, sshk);
dss->x = getmp(&pb, &priv_len);
if (!dss->x) {
dss_freekey(&dss->sshk);
@ -382,13 +384,15 @@ static void dss_openssh_fmtkey(ssh_key *key, BinarySink *bs)
static int dss_pubkey_bits(const ssh_keyalg *self,
const void *blob, int len)
{
ssh_key *sshk;
struct dss_key *dss;
int ret;
dss = FROMFIELD(dss_newkey(self, blob, len),
struct dss_key, sshk);
if (!dss)
sshk = dss_newkey(self, blob, len);
if (!sshk)
return -1;
dss = FROMFIELD(sshk, struct dss_key, sshk);
ret = bignum_bitcount(dss->p);
dss_freekey(&dss->sshk);