1
1

Add error checking to publickey_make_dss().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@429 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
Andreas Schneider 2009-04-08 12:52:32 +00:00
родитель befca1dc8a
Коммит 8948bf41f1

Просмотреть файл

@ -67,8 +67,11 @@ int ssh_type_from_name(const char *name) {
} }
PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer) { PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer) {
STRING *p,*q,*g,*pubkey; STRING *p = NULL;
PUBLIC_KEY *key; STRING *q = NULL;
STRING *g = NULL;
STRING *pubkey = NULL;
PUBLIC_KEY *key = NULL;
key = malloc(sizeof(PUBLIC_KEY)); key = malloc(sizeof(PUBLIC_KEY));
if (key == NULL) { if (key == NULL) {
@ -77,37 +80,68 @@ PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer){
key->type=TYPE_DSS; key->type=TYPE_DSS;
key->type_c="ssh-dss"; key->type_c="ssh-dss";
p = buffer_get_ssh_string(buffer); p = buffer_get_ssh_string(buffer);
q = buffer_get_ssh_string(buffer); q = buffer_get_ssh_string(buffer);
g = buffer_get_ssh_string(buffer); g = buffer_get_ssh_string(buffer);
pubkey = buffer_get_ssh_string(buffer); pubkey = buffer_get_ssh_string(buffer);
buffer_free(buffer); /* we don't need it anymore */ buffer_free(buffer); /* we don't need it anymore */
if(!p || !q || !g || !pubkey){
if (p == NULL || q == NULL || g == NULL || pubkey == NULL) {
ssh_set_error(session, SSH_FATAL, "Invalid DSA public key"); ssh_set_error(session, SSH_FATAL, "Invalid DSA public key");
if(p) goto error;
free(p);
if(q)
free(q);
if(g)
free(g);
if(pubkey)
free(pubkey);
free(key);
return NULL;
} }
#ifdef HAVE_LIBGCRYPT #ifdef HAVE_LIBGCRYPT
gcry_sexp_build(&key->dsa_pub,NULL,"(public-key(dsa(p %b)(q %b)(g %b)(y %b)))",string_len(p),p->string,string_len(q),q->string,string_len(g),g->string,string_len(pubkey),pubkey->string); gcry_sexp_build(&key->dsa_pub, NULL,
"(public-key(dsa(p %b)(q %b)(g %b)(y %b)))",
string_len(p), p->string,
string_len(q), q->string,
string_len(g), g->string,
string_len(pubkey), pubkey->string);
if (key->dsa_pub == NULL) {
goto error;
}
#elif defined HAVE_LIBCRYPTO #elif defined HAVE_LIBCRYPTO
key->dsa_pub = DSA_new(); key->dsa_pub = DSA_new();
if (key->dsa_pub == NULL) {
goto error;
}
key->dsa_pub->p = make_string_bn(p); key->dsa_pub->p = make_string_bn(p);
key->dsa_pub->q = make_string_bn(q); key->dsa_pub->q = make_string_bn(q);
key->dsa_pub->g = make_string_bn(g); key->dsa_pub->g = make_string_bn(g);
key->dsa_pub->pub_key = make_string_bn(pubkey); key->dsa_pub->pub_key = make_string_bn(pubkey);
#endif if (key->dsa_pub->p == NULL ||
free(p); key->dsa_pub->q == NULL ||
free(q); key->dsa_pub->g == NULL ||
free(g); key->dsa_pub->pub_key == NULL) {
free(pubkey); goto error;
}
#endif /* HAVE_LIBCRYPTO */
string_burn(p);
string_free(p);
string_burn(q);
string_free(q);
string_burn(g);
string_free(g);
string_burn(pubkey);
string_free(pubkey);
return key;
error:
string_burn(p);
string_free(p);
string_burn(q);
string_free(q);
string_burn(g);
string_free(g);
string_burn(pubkey);
string_free(pubkey);
publickey_free(key);
return key; return key;
} }