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:
16
sshdss.c
16
sshdss.c
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user