summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2002-01-13 17:57:38 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2002-01-13 17:57:38 +0000
commitbca445d4ff6104e798b8784e718734efeac05ccc (patch)
tree14e1b35db627e39dcd2d6d50244befdd5af0c295 /usr.bin
parentd5692244c6cf7216e4510fa5c316af165e255aa7 (diff)
use buffer API and avoid static strings of fixed size; ok provos@/mouring@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/auth2-chall.c20
-rw-r--r--usr.bin/ssh/auth2.c27
-rw-r--r--usr.bin/ssh/compat.c18
-rw-r--r--usr.bin/ssh/sshconnect2.c21
-rw-r--r--usr.bin/ssh/sshd.c24
5 files changed, 56 insertions, 54 deletions
diff --git a/usr.bin/ssh/auth2-chall.c b/usr.bin/ssh/auth2-chall.c
index a1f96392e1f..9f1d932756b 100644
--- a/usr.bin/ssh/auth2-chall.c
+++ b/usr.bin/ssh/auth2-chall.c
@@ -23,10 +23,11 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
-RCSID("$OpenBSD: auth2-chall.c,v 1.15 2002/01/11 23:02:51 markus Exp $");
+RCSID("$OpenBSD: auth2-chall.c,v 1.16 2002/01/13 17:57:37 markus Exp $");
#include "ssh2.h"
#include "auth.h"
+#include "buffer.h"
#include "packet.h"
#include "xmalloc.h"
#include "dispatch.h"
@@ -68,22 +69,25 @@ static KbdintAuthctxt *
kbdint_alloc(const char *devs)
{
KbdintAuthctxt *kbdintctxt;
+ Buffer b;
int i;
- char buf[1024];
kbdintctxt = xmalloc(sizeof(KbdintAuthctxt));
if (strcmp(devs, "") == 0) {
- buf[0] = '\0';
+ buffer_init(&b);
for (i = 0; devices[i]; i++) {
- if (i != 0)
- strlcat(buf, ",", sizeof(buf));
- strlcat(buf, devices[i]->name, sizeof(buf));
+ if (buffer_len(&b) > 0)
+ buffer_append(&b, ",", 1);
+ buffer_append(&b, devices[i]->name,
+ strlen(devices[i]->name));
}
- debug("kbdint_alloc: devices '%s'", buf);
- kbdintctxt->devices = xstrdup(buf);
+ buffer_append(&b, "\0", 1);
+ kbdintctxt->devices = xstrdup(buffer_ptr(&b));
+ buffer_free(&b);
} else {
kbdintctxt->devices = xstrdup(devs);
}
+ debug("kbdint_alloc: devices '%s'", kbdintctxt->devices);
kbdintctxt->ctxt = NULL;
kbdintctxt->device = NULL;
diff --git a/usr.bin/ssh/auth2.c b/usr.bin/ssh/auth2.c
index bd389d86b24..6def8f6769d 100644
--- a/usr.bin/ssh/auth2.c
+++ b/usr.bin/ssh/auth2.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: auth2.c,v 1.81 2002/01/11 13:39:36 markus Exp $");
+RCSID("$OpenBSD: auth2.c,v 1.82 2002/01/13 17:57:37 markus Exp $");
#include <openssl/evp.h>
@@ -533,31 +533,22 @@ static char *
authmethods_get(void)
{
Authmethod *method = NULL;
- u_int size = 0;
+ Buffer b;
char *list;
+ buffer_init(&b);
for (method = authmethods; method->name != NULL; method++) {
if (strcmp(method->name, "none") == 0)
continue;
if (method->enabled != NULL && *(method->enabled) != 0) {
- if (size != 0)
- size += strlen(DELIM);
- size += strlen(method->name);
- }
- }
- size++; /* trailing '\0' */
- list = xmalloc(size);
- list[0] = '\0';
-
- for (method = authmethods; method->name != NULL; method++) {
- if (strcmp(method->name, "none") == 0)
- continue;
- if (method->enabled != NULL && *(method->enabled) != 0) {
- if (list[0] != '\0')
- strlcat(list, DELIM, size);
- strlcat(list, method->name, size);
+ if (buffer_len(&b) > 0)
+ buffer_append(&b, ",", 1);
+ buffer_append(&b, method->name, strlen(method->name));
}
}
+ buffer_append(&b, "\0", 1);
+ list = xstrdup(buffer_ptr(&b));
+ buffer_free(&b);
return list;
}
diff --git a/usr.bin/ssh/compat.c b/usr.bin/ssh/compat.c
index 3f8d1c041f9..6a9ba465384 100644
--- a/usr.bin/ssh/compat.c
+++ b/usr.bin/ssh/compat.c
@@ -23,8 +23,9 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: compat.c,v 1.56 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: compat.c,v 1.57 2002/01/13 17:57:37 markus Exp $");
+#include "buffer.h"
#include "packet.h"
#include "xmalloc.h"
#include "compat.h"
@@ -182,24 +183,25 @@ proto_spec(const char *spec)
char *
compat_cipher_proposal(char *cipher_prop)
{
+ Buffer b;
char *orig_prop, *fix_ciphers;
char *cp, *tmp;
- size_t len;
if (!(datafellows & SSH_BUG_BIGENDIANAES))
return(cipher_prop);
- len = strlen(cipher_prop) + 1;
- fix_ciphers = xmalloc(len);
- *fix_ciphers = '\0';
+ buffer_init(&b);
tmp = orig_prop = xstrdup(cipher_prop);
while ((cp = strsep(&tmp, ",")) != NULL) {
if (strncmp(cp, "aes", 3) && strncmp(cp, "rijndael", 8)) {
- if (*fix_ciphers)
- strlcat(fix_ciphers, ",", len);
- strlcat(fix_ciphers, cp, len);
+ if (buffer_len(&b) > 0)
+ buffer_append(&b, ",", 1);
+ buffer_append(&b, cp, strlen(cp));
}
}
+ buffer_append(&b, "\0", 1);
+ fix_ciphers = xstrdup(buffer_ptr(&b));
+ buffer_free(&b);
xfree(orig_prop);
debug2("Original cipher proposal: %s", cipher_prop);
debug2("Compat cipher proposal: %s", fix_ciphers);
diff --git a/usr.bin/ssh/sshconnect2.c b/usr.bin/ssh/sshconnect2.c
index a565f73cc47..3e5ca7ad119 100644
--- a/usr.bin/ssh/sshconnect2.c
+++ b/usr.bin/ssh/sshconnect2.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: sshconnect2.c,v 1.92 2001/12/28 15:06:00 markus Exp $");
+RCSID("$OpenBSD: sshconnect2.c,v 1.93 2002/01/13 17:57:37 markus Exp $");
#include <openssl/bn.h>
#include <openssl/md5.h>
@@ -991,22 +991,23 @@ authmethod_get(char *authlist)
}
}
-
-#define DELIM ","
-
static char *
authmethods_get(void)
{
Authmethod *method = NULL;
- char buf[1024];
+ Buffer b;
+ char *list;
- buf[0] = '\0';
+ buffer_init(&b);
for (method = authmethods; method->name != NULL; method++) {
if (authmethod_is_enabled(method)) {
- if (buf[0] != '\0')
- strlcat(buf, DELIM, sizeof buf);
- strlcat(buf, method->name, sizeof buf);
+ if (buffer_len(&b) > 0)
+ buffer_append(&b, ",", 1);
+ buffer_append(&b, method->name, strlen(method->name));
}
}
- return xstrdup(buf);
+ buffer_append(&b, "\0", 1);
+ list = xstrdup(buffer_ptr(&b));
+ buffer_free(&b);
+ return list;
}
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index faaf2614e57..4afb27e8e1a 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -40,7 +40,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: sshd.c,v 1.222 2001/12/28 14:50:54 markus Exp $");
+RCSID("$OpenBSD: sshd.c,v 1.223 2002/01/13 17:57:37 markus Exp $");
#include <openssl/dh.h>
#include <openssl/bn.h>
@@ -471,9 +471,11 @@ destroy_sensitive_data(void)
static char *
list_hostkey_types(void)
{
- static char buf[1024];
+ Buffer b;
+ char *p;
int i;
- buf[0] = '\0';
+
+ buffer_init(&b);
for (i = 0; i < options.num_host_key_files; i++) {
Key *key = sensitive_data.host_keys[i];
if (key == NULL)
@@ -481,16 +483,18 @@ list_hostkey_types(void)
switch (key->type) {
case KEY_RSA:
case KEY_DSA:
- strlcat(buf, key_ssh_name(key), sizeof buf);
- strlcat(buf, ",", sizeof buf);
+ if (buffer_len(&b) > 0)
+ buffer_append(&b, ",", 1);
+ p = key_ssh_name(key);
+ buffer_append(&b, p, strlen(p));
break;
}
}
- i = strlen(buf);
- if (i > 0 && buf[i-1] == ',')
- buf[i-1] = '\0';
- debug("list_hostkey_types: %s", buf);
- return buf;
+ buffer_append(&b, "\0", 1);
+ p = xstrdup(buffer_ptr(&b));
+ buffer_free(&b);
+ debug("list_hostkey_types: %s", p);
+ return p;
}
static Key *