diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2010-10-20 14:47:11 +0200 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2010-10-20 14:47:11 +0200 |
commit | 98221f4e3640b2522851e49c7f81f5e500ed4a25 (patch) | |
tree | f1dc9608ec61cfb2d73a64580589b6746a04c198 | |
parent | 8e2699e16139c8efdc54a06471de29966ccc233a (diff) | |
download | libssh-98221f4e3640b2522851e49c7f81f5e500ed4a25.tar.gz libssh-98221f4e3640b2522851e49c7f81f5e500ed4a25.tar.xz libssh-98221f4e3640b2522851e49c7f81f5e500ed4a25.zip |
Fixed a bunch of smallish bugs
http://linuxtesting.org/upstream-tracker/test_results/libssh/current/test_results.html
for a whole list
-rw-r--r-- | src/auth.c | 25 | ||||
-rw-r--r-- | src/dh.c | 11 | ||||
-rw-r--r-- | src/keyfiles.c | 21 | ||||
-rw-r--r-- | src/keys.c | 8 | ||||
-rw-r--r-- | src/string.c | 8 |
5 files changed, 56 insertions, 17 deletions
@@ -423,6 +423,12 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username, ssh_string algo = NULL; int rc = SSH_AUTH_ERROR; + if(session==NULL) + return SSH_AUTH_ERROR; + if(publickey==NULL){ + ssh_set_error(session,SSH_FATAL,"invalid arguments"); + return SSH_AUTH_ERROR; + } enter_function(); #ifdef WITH_SSH1 @@ -540,6 +546,12 @@ int ssh_userauth_pubkey(ssh_session session, const char *username, ssh_string pkstr = NULL; int rc = SSH_AUTH_ERROR; + if(session==NULL) + return SSH_AUTH_ERROR; + if(privatekey==NULL){ + ssh_set_error(session,SSH_FATAL,"invalid arguments"); + return SSH_AUTH_ERROR; + } enter_function(); #if 0 @@ -1583,6 +1595,8 @@ int ssh_userauth_kbdint(ssh_session session, const char *user, * @returns The number of prompts. */ int ssh_userauth_kbdint_getnprompts(ssh_session session) { + if(session==NULL || session->kbdint == NULL) + return SSH_ERROR; return session->kbdint->nprompts; } @@ -1597,6 +1611,8 @@ int ssh_userauth_kbdint_getnprompts(ssh_session session) { * @returns The name of the message block. Do not free it. */ const char *ssh_userauth_kbdint_getname(ssh_session session) { + if(session==NULL || session->kbdint == NULL) + return NULL; return session->kbdint->name; } @@ -1612,6 +1628,8 @@ const char *ssh_userauth_kbdint_getname(ssh_session session) { */ const char *ssh_userauth_kbdint_getinstruction(ssh_session session) { + if(session==NULL || session->kbdint == NULL) + return NULL; return session->kbdint->instruction; } @@ -1633,7 +1651,9 @@ const char *ssh_userauth_kbdint_getinstruction(ssh_session session) { */ const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo) { - if (i > session->kbdint->nprompts) { + if(session==NULL || session->kbdint == NULL) + return NULL; + if (i > session->kbdint->nprompts) { return NULL; } @@ -1660,7 +1680,8 @@ const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, */ int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i, const char *answer) { - if (session == NULL || answer == NULL || i > session->kbdint->nprompts) { + if (session == NULL || answer == NULL || session->kbdint == NULL || + i > session->kbdint->nprompts) { return -1; } @@ -832,23 +832,24 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) { unsigned char *h; if (session == NULL || hash == NULL) { - return -1; + return SSH_ERROR; } *hash = NULL; if (session->current_crypto == NULL || session->current_crypto->server_pubkey == NULL){ ssh_set_error(session,SSH_FATAL,"No current cryptographic context"); + return SSH_ERROR; } h = malloc(sizeof(unsigned char *) * MD5_DIGEST_LEN); if (h == NULL) { - return -1; + return SSH_ERROR; } ctx = md5_init(); if (ctx == NULL) { SAFE_FREE(h); - return -1; + return SSH_ERROR; } pubkey = session->current_crypto->server_pubkey; @@ -877,6 +878,10 @@ void ssh_clean_pubkey_hash(unsigned char **hash) { } ssh_string ssh_get_pubkey(ssh_session session){ + if(session==NULL || session->current_crypto ==NULL || + session->current_crypto->server_pubkey==NULL) + return NULL; + else return ssh_string_copy(session->current_crypto->server_pubkey); } diff --git a/src/keyfiles.c b/src/keyfiles.c index 08169787..e7351f07 100644 --- a/src/keyfiles.c +++ b/src/keyfiles.c @@ -802,7 +802,7 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename, #endif return NULL; } - + ZERO_STRUCTP(privkey); privkey->type = type; privkey->dsa_priv = dsa; privkey->rsa_priv = rsa; @@ -955,23 +955,28 @@ int ssh_publickey_to_file(ssh_session session, const char *file, unsigned char *pubkey_64; size_t len; int rc; - + if(session==NULL) + return SSH_ERROR; + if(file==NULL || pubkey==NULL){ + ssh_set_error(session, SSH_FATAL, "Invalid parameters"); + return SSH_ERROR; + } pubkey_64 = bin_to_base64(pubkey->string, ssh_string_len(pubkey)); if (pubkey_64 == NULL) { - return -1; + return SSH_ERROR; } user = ssh_get_local_username(session); if (user == NULL) { SAFE_FREE(pubkey_64); - return -1; + return SSH_ERROR; } rc = gethostname(host, sizeof(host)); if (rc < 0) { SAFE_FREE(user); SAFE_FREE(pubkey_64); - return -1; + return SSH_ERROR; } snprintf(buffer, sizeof(buffer), "%s %s %s@%s\n", @@ -990,7 +995,7 @@ int ssh_publickey_to_file(ssh_session session, const char *file, if (fp == NULL) { ssh_set_error(session, SSH_REQUEST_DENIED, "Error opening %s: %s", file, strerror(errno)); - return -1; + return SSH_ERROR; } len = strlen(buffer); @@ -999,11 +1004,11 @@ int ssh_publickey_to_file(ssh_session session, const char *file, "Unable to write to %s", file); fclose(fp); unlink(file); - return -1; + return SSH_ERROR; } fclose(fp); - return 0; + return SSH_OK; } /** @@ -329,7 +329,7 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) { if (key == NULL) { return NULL; } - + ZERO_STRUCTP(key); key->type = prv->type; switch(key->type) { case SSH_KEYTYPE_DSS: @@ -466,6 +466,9 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) { } #endif break; + default: + publickey_free(key); + return NULL; } key->type_c = ssh_type_to_char(prv->type); @@ -715,7 +718,8 @@ ssh_string publickey_to_string(ssh_public_key key) { ssh_string_fill(ret, buffer_get_rest(buf), buffer_get_rest_len(buf)); error: ssh_buffer_free(buf); - ssh_string_free(type); + if(type != NULL) + ssh_string_free(type); return ret; } diff --git a/src/string.c b/src/string.c index 06042aea..33920e68 100644 --- a/src/string.c +++ b/src/string.c @@ -131,8 +131,12 @@ size_t ssh_string_len(struct ssh_string_struct *s) { * string may not be readable with regular libc functions. */ char *ssh_string_to_char(struct ssh_string_struct *s) { - size_t len = ntohl(s->size) + 1; - char *new = malloc(len); + size_t len; + char *new; + if(s==NULL) + return NULL; + len = ntohl(s->size) + 1; + new = malloc(len); if (new == NULL) { return NULL; |