Add memory error checking to keyfile functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@319 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
b4c65e41f6
Коммит
ddd10236bd
@ -223,6 +223,7 @@ static int privatekey_decrypt(int algo, int mode, unsigned int key_len,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy(buffer_get(data), tmp, buffer_get_len(data));
|
memcpy(buffer_get(data), tmp, buffer_get_len(data));
|
||||||
|
SAFE_FREE(tmp);
|
||||||
gcry_cipher_close(cipher);
|
gcry_cipher_close(cipher);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -275,6 +276,9 @@ static int privatekey_dek_header(char *header, unsigned int header_len,
|
|||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
*iv = malloc(*iv_len);
|
*iv = malloc(*iv_len);
|
||||||
|
if (*iv == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
load_iv(header + iv_pos, *iv, *iv_len);
|
load_iv(header + iv_pos, *iv, *iv_len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -580,7 +584,10 @@ PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session,char *filename,int type,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
privkey=malloc(sizeof(PRIVATE_KEY));
|
privkey = malloc(sizeof(PRIVATE_KEY));
|
||||||
|
if (privkey == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
privkey->type=type;
|
privkey->type=type;
|
||||||
privkey->dsa_priv=dsa;
|
privkey->dsa_priv=dsa;
|
||||||
privkey->rsa_priv=rsa;
|
privkey->rsa_priv=rsa;
|
||||||
@ -640,7 +647,10 @@ PRIVATE_KEY *_privatekey_from_file(void *session,char *filename,int type){
|
|||||||
ssh_set_error(session,SSH_FATAL,"Invalid private key type %d",type);
|
ssh_set_error(session,SSH_FATAL,"Invalid private key type %d",type);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
privkey=malloc(sizeof(PRIVATE_KEY));
|
privkey = malloc(sizeof(PRIVATE_KEY));
|
||||||
|
if (privkey == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
privkey->type=type;
|
privkey->type=type;
|
||||||
privkey->dsa_priv=dsa;
|
privkey->dsa_priv=dsa;
|
||||||
privkey->rsa_priv=rsa;
|
privkey->rsa_priv=rsa;
|
||||||
@ -921,6 +931,10 @@ static int check_public_key(SSH_SESSION *session, char **tokens){
|
|||||||
/* do it manually instead */
|
/* do it manually instead */
|
||||||
len = bignum_num_bytes(tmpbn);
|
len = bignum_num_bytes(tmpbn);
|
||||||
tmpstring = malloc(4 + len);
|
tmpstring = malloc(4 + len);
|
||||||
|
if (tmpstring == NULL) {
|
||||||
|
return -1;
|
||||||
|
ssh_set_error(session, SSH_FATAL, "No space left");
|
||||||
|
}
|
||||||
tmpstring->size = htonl(len);
|
tmpstring->size = htonl(len);
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
bignum_bn2bin(tmpbn, len, tmpstring->string);
|
bignum_bn2bin(tmpbn, len, tmpstring->string);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user