summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/sshd.c
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2016-05-02 08:49:04 +0000
committerDamien Miller <djm@cvs.openbsd.org>2016-05-02 08:49:04 +0000
commitc023ffcde78b7ab576e1ea3f34aafba31470877d (patch)
tree1528611b6288037a1483a5985b86f6a7e0653b2a /usr.bin/ssh/sshd.c
parente745dff34c8b0de52da4f946c480d9cae831323c (diff)
fix signed/unsigned errors reported by clang-3.7; add
sshbuf_dup_string() to replace a common idiom of strdup(sshbuf_ptr()) with better safety checking; feedback and ok markus@
Diffstat (limited to 'usr.bin/ssh/sshd.c')
-rw-r--r--usr.bin/ssh/sshd.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index 6a51b9d56f5..50068b81250 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshd.c,v 1.466 2016/03/07 19:02:43 djm Exp $ */
+/* $OpenBSD: sshd.c,v 1.467 2016/05/02 08:49:03 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -807,8 +807,8 @@ list_hostkey_types(void)
break;
}
}
- buffer_append(&b, "\0", 1);
- ret = xstrdup(buffer_ptr(&b));
+ if ((ret = sshbuf_dup_string(&b)) == NULL)
+ fatal("%s: sshbuf_dup_string failed", __func__);
buffer_free(&b);
debug("list_hostkey_types: %s", ret);
return ret;
@@ -989,12 +989,13 @@ usage(void)
}
static void
-send_rexec_state(int fd, Buffer *conf)
+send_rexec_state(int fd, struct sshbuf *conf)
{
- Buffer m;
+ struct sshbuf *m;
+ int r;
- debug3("%s: entering fd = %d config len %d", __func__, fd,
- buffer_len(conf));
+ debug3("%s: entering fd = %d config len %zu", __func__, fd,
+ sshbuf_len(conf));
/*
* Protocol from reexec master to child:
@@ -1007,27 +1008,37 @@ send_rexec_state(int fd, Buffer *conf)
* bignum p "
* bignum q "
*/
- buffer_init(&m);
- buffer_put_cstring(&m, buffer_ptr(conf));
+ if ((m = sshbuf_new()) == NULL)
+ fatal("%s: sshbuf_new failed", __func__);
+ if ((r = sshbuf_put_stringb(m, conf)) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
#ifdef WITH_SSH1
if (sensitive_data.server_key != NULL &&
sensitive_data.server_key->type == KEY_RSA1) {
- buffer_put_int(&m, 1);
- buffer_put_bignum(&m, sensitive_data.server_key->rsa->e);
- buffer_put_bignum(&m, sensitive_data.server_key->rsa->n);
- buffer_put_bignum(&m, sensitive_data.server_key->rsa->d);
- buffer_put_bignum(&m, sensitive_data.server_key->rsa->iqmp);
- buffer_put_bignum(&m, sensitive_data.server_key->rsa->p);
- buffer_put_bignum(&m, sensitive_data.server_key->rsa->q);
+ if ((r = sshbuf_put_u32(m, 1)) != 0 ||
+ (r = sshbuf_put_bignum1(m,
+ sensitive_data.server_key->rsa->e)) != 0 ||
+ (r = sshbuf_put_bignum1(m,
+ sensitive_data.server_key->rsa->n)) != 0 ||
+ (r = sshbuf_put_bignum1(m,
+ sensitive_data.server_key->rsa->d)) != 0 ||
+ (r = sshbuf_put_bignum1(m,
+ sensitive_data.server_key->rsa->iqmp)) != 0 ||
+ (r = sshbuf_put_bignum1(m,
+ sensitive_data.server_key->rsa->p)) != 0 ||
+ (r = sshbuf_put_bignum1(m,
+ sensitive_data.server_key->rsa->q)) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
} else
#endif
- buffer_put_int(&m, 0);
+ if ((r = sshbuf_put_u32(m, 1)) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
- if (ssh_msg_send(fd, 0, &m) == -1)
+ if (ssh_msg_send(fd, 0, m) == -1)
fatal("%s: ssh_msg_send failed", __func__);
- buffer_free(&m);
+ sshbuf_free(m);
debug3("%s: done", __func__);
}