aboutsummaryrefslogtreecommitdiff
path: root/libssh/kex.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-07 19:50:41 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-07 19:50:41 +0000
commitc4f65cb5dde1b9b90d52d1d444c519cc66a8b656 (patch)
tree33c817c84b2570853365ff4c98b4f4633b685d84 /libssh/kex.c
parent586ed9103f4bc125acb7868b1242d971bdf6d7ef (diff)
downloadlibssh-c4f65cb5dde1b9b90d52d1d444c519cc66a8b656.tar.gz
libssh-c4f65cb5dde1b9b90d52d1d444c519cc66a8b656.tar.xz
libssh-c4f65cb5dde1b9b90d52d1d444c519cc66a8b656.zip
Add error checking for make_rsa1_string().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@423 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/kex.c')
-rw-r--r--libssh/kex.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/libssh/kex.c b/libssh/kex.c
index 82b29db5..eaf595c6 100644
--- a/libssh/kex.c
+++ b/libssh/kex.c
@@ -442,17 +442,34 @@ int verify_existing_algo(int algo, const char *name){
/* makes a STRING contating 3 strings : ssh-rsa1,e and n */
/* this is a public key in openssh's format */
static STRING *make_rsa1_string(STRING *e, STRING *n){
- BUFFER *buffer=buffer_new();
- STRING *rsa=string_from_char("ssh-rsa1");
- STRING *ret;
- buffer_add_ssh_string(buffer,rsa);
- free(rsa);
- buffer_add_ssh_string(buffer,e);
- buffer_add_ssh_string(buffer,n);
- ret=string_new(buffer_get_len(buffer));
- string_fill(ret,buffer_get(buffer),buffer_get_len(buffer));
- buffer_free(buffer);
- return ret;
+ BUFFER *buffer = NULL;
+ STRING *rsa = NULL;
+ STRING *ret = NULL;
+
+ buffer = buffer_new();
+ rsa = string_from_char("ssh-rsa1");
+
+ if (buffer_add_ssh_string(buffer, rsa) < 0) {
+ goto error;
+ }
+ if (buffer_add_ssh_string(buffer, e) < 0) {
+ goto error;
+ }
+ if (buffer_add_ssh_string(buffer, n) < 0) {
+ goto error;
+ }
+
+ ret = string_new(buffer_get_len(buffer));
+ if (ret == NULL) {
+ goto error;
+ }
+
+ string_fill(ret, buffer_get(buffer), buffer_get_len(buffer));
+error:
+ buffer_free(buffer);
+ string_free(rsa);
+
+ return ret;
}
/* TODO FIXME add return value and error checking in callers */