From f7ecade3a06b94137bb3f1daef9184d5d3df17fb Mon Sep 17 00:00:00 2001 From: Markus Friedl Date: Tue, 21 Feb 2012 02:51:09 +0100 Subject: [PATCH] make sshbuf_get_stringb() a public API --- ssh/packet.c | 30 ++++-------------------------- ssh/sshbuf-getput-basic.c | 20 ++++++++++++++++++++ ssh/sshbuf.h | 1 + 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/ssh/packet.c b/ssh/packet.c index e5b51a9..951f711 100644 --- a/ssh/packet.c +++ b/ssh/packet.c @@ -201,8 +201,6 @@ struct session_state { TAILQ_HEAD(, packet) outgoing; }; -static int _sshbuf_get_stringb(struct sshbuf *, struct sshbuf *); - struct ssh * ssh_alloc_session_state(void) { @@ -423,7 +421,7 @@ ssh_packet_set_compress_state(struct ssh *ssh, struct sshbuf *m) if ((b = sshbuf_new()) == NULL) return SSH_ERR_ALLOC_FAIL; - if ((r = _sshbuf_get_stringb(m, b)) != 0) + if ((r = sshbuf_get_stringb(m, b)) != 0) goto out; if ((r = sshbuf_get_string_direct(b, &inblob, &inl)) != 0 || (r = sshbuf_get_string_direct(b, &outblob, &outl)) != 0) @@ -2529,26 +2527,6 @@ ssh_packet_get_state(struct ssh *ssh, struct sshbuf *m) return 0; } -static int -_sshbuf_get_stringb(struct sshbuf *buf, struct sshbuf *v) -{ - u_char *p; - u_int32_t len; - int r; - - /* - * Use sshbuf_peek_string_direct() to figure out if there is - * a complete string in 'buf' and copy the string directly - * into 'v'. - */ - if ((r = sshbuf_peek_string_direct(buf, NULL, NULL)) != 0 || - (r = sshbuf_get_u32(buf, &len)) != 0 || - (r = sshbuf_reserve(v, len, &p)) != 0 || - (r = sshbuf_get(buf, p, len)) != 0) - return r; - return 0; -} - /* restore key exchange results from blob for packet state de-serialization */ static int newkeys_from_blob(struct sshbuf *m, struct ssh *ssh, int mode) @@ -2566,7 +2544,7 @@ newkeys_from_blob(struct sshbuf *m, struct ssh *ssh, int mode) r = SSH_ERR_ALLOC_FAIL; goto out; } - if ((r = _sshbuf_get_stringb(m, b)) != 0) + if ((r = sshbuf_get_stringb(m, b)) != 0) goto out; #ifdef DEBUG_PK sshbuf_dump(b, stderr); @@ -2629,8 +2607,8 @@ kex_from_blob(Buffer *m, Kex **kexp) (r = sshbuf_get_u32(m, &kex->we_need)) != 0 || (r = sshbuf_get_u32(m, &kex->hostkey_type)) != 0 || (r = sshbuf_get_u32(m, &kex->kex_type)) != 0 || - (r = _sshbuf_get_stringb(m, kex->my)) != 0 || - (r = _sshbuf_get_stringb(m, kex->peer)) != 0 || + (r = sshbuf_get_stringb(m, kex->my)) != 0 || + (r = sshbuf_get_stringb(m, kex->peer)) != 0 || (r = sshbuf_get_u32(m, &kex->flags)) != 0 || (r = sshbuf_get_cstring(m, &kex->client_version_string, NULL)) != 0 || (r = sshbuf_get_cstring(m, &kex->server_version_string, NULL)) != 0) diff --git a/ssh/sshbuf-getput-basic.c b/ssh/sshbuf-getput-basic.c index 1750d02..2f6852e 100644 --- a/ssh/sshbuf-getput-basic.c +++ b/ssh/sshbuf-getput-basic.c @@ -192,6 +192,26 @@ sshbuf_get_cstring(struct sshbuf *buf, char **valp, size_t *lenp) return 0; } +int +sshbuf_get_stringb(struct sshbuf *buf, struct sshbuf *v) +{ + u_int32_t len; + u_char *p; + int r; + + /* + * Use sshbuf_peek_string_direct() to figure out if there is + * a complete string in 'buf' and copy the string directly + * into 'v'. + */ + if ((r = sshbuf_peek_string_direct(buf, NULL, NULL)) != 0 || + (r = sshbuf_get_u32(buf, &len)) != 0 || + (r = sshbuf_reserve(v, len, &p)) != 0 || + (r = sshbuf_get(buf, p, len)) != 0) + return r; + return 0; +} + int sshbuf_put(struct sshbuf *buf, const void *v, size_t len) { diff --git a/ssh/sshbuf.h b/ssh/sshbuf.h index 29cd9f9..c805f0b 100644 --- a/ssh/sshbuf.h +++ b/ssh/sshbuf.h @@ -146,6 +146,7 @@ int sshbuf_put_u8(struct sshbuf *buf, u_char val); */ int sshbuf_get_string(struct sshbuf *buf, u_char **valp, size_t *lenp); int sshbuf_get_cstring(struct sshbuf *buf, char **valp, size_t *lenp); +int sshbuf_get_stringb(struct sshbuf *buf, struct sshbuf *v); int sshbuf_put_string(struct sshbuf *buf, const void *v, size_t len); int sshbuf_put_cstring(struct sshbuf *buf, const char *v); int sshbuf_put_stringb(struct sshbuf *buf, const struct sshbuf *v);