From a06cba944488780784cecf31d7789e93f4287410 Mon Sep 17 00:00:00 2001 From: djm Date: Mon, 28 Apr 2014 03:09:18 +0000 Subject: [PATCH] buffer_get_string_ptr's return should be const to remind callers that futzing with it will futz with the actual buffer contents --- usr.bin/ssh/authfile.c | 5 +++-- usr.bin/ssh/bufaux.c | 8 ++++---- usr.bin/ssh/buffer.h | 6 +++--- usr.bin/ssh/channels.c | 4 ++-- usr.bin/ssh/krl.c | 8 +++++--- usr.bin/ssh/mux.c | 6 +++--- usr.bin/ssh/packet.c | 4 ++-- usr.bin/ssh/packet.h | 4 ++-- usr.bin/ssh/ssh-keygen.c | 12 ++++++------ 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/usr.bin/ssh/authfile.c b/usr.bin/ssh/authfile.c index f258faaafbb..19b0c619342 100644 --- a/usr.bin/ssh/authfile.c +++ b/usr.bin/ssh/authfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: authfile.c,v 1.104 2014/03/12 04:51:12 djm Exp $ */ +/* $OpenBSD: authfile.c,v 1.105 2014/04/28 03:09:18 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -197,7 +197,8 @@ key_parse_private2(Buffer *blob, int type, const char *passphrase, char **commentp) { u_char *key = NULL, *cp, *salt = NULL, pad, last; - char *comment = NULL, *ciphername = NULL, *kdfname = NULL, *kdfp; + char *comment = NULL, *ciphername = NULL, *kdfname = NULL; + const u_char *kdfp; u_int keylen = 0, ivlen, blocksize, slen, klen, len, rounds, nkeys; u_int check1, check2, m1len, m2len; size_t authlen; diff --git a/usr.bin/ssh/bufaux.c b/usr.bin/ssh/bufaux.c index b946b24bb7b..61eb26643bb 100644 --- a/usr.bin/ssh/bufaux.c +++ b/usr.bin/ssh/bufaux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bufaux.c,v 1.57 2014/04/16 23:22:45 djm Exp $ */ +/* $OpenBSD: bufaux.c,v 1.58 2014/04/28 03:09:18 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -234,7 +234,7 @@ buffer_get_cstring(Buffer *buffer, u_int *length_ptr) return ret; } -void * +const void * buffer_get_string_ptr_ret(Buffer *buffer, u_int *length_ptr) { void *ptr; @@ -253,10 +253,10 @@ buffer_get_string_ptr_ret(Buffer *buffer, u_int *length_ptr) return (ptr); } -void * +const void * buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr) { - void *ret; + const void *ret; if ((ret = buffer_get_string_ptr_ret(buffer, length_ptr)) == NULL) fatal("buffer_get_string_ptr: buffer error"); diff --git a/usr.bin/ssh/buffer.h b/usr.bin/ssh/buffer.h index 23ec43c5352..aca360a4124 100644 --- a/usr.bin/ssh/buffer.h +++ b/usr.bin/ssh/buffer.h @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.h,v 1.23 2014/01/12 08:13:13 djm Exp $ */ +/* $OpenBSD: buffer.h,v 1.24 2014/04/28 03:09:18 djm Exp $ */ /* * Author: Tatu Ylonen @@ -66,7 +66,7 @@ int buffer_get_char(Buffer *); void buffer_put_char(Buffer *, int); void *buffer_get_string(Buffer *, u_int *); -void *buffer_get_string_ptr(Buffer *, u_int *); +const void *buffer_get_string_ptr(Buffer *, u_int *); void buffer_put_string(Buffer *, const void *, u_int); char *buffer_get_cstring(Buffer *, u_int *); void buffer_put_cstring(Buffer *, const char *); @@ -83,7 +83,7 @@ int buffer_get_int_ret(u_int *, Buffer *); int buffer_get_int64_ret(u_int64_t *, Buffer *); void *buffer_get_string_ret(Buffer *, u_int *); char *buffer_get_cstring_ret(Buffer *, u_int *); -void *buffer_get_string_ptr_ret(Buffer *, u_int *); +const void *buffer_get_string_ptr_ret(Buffer *, u_int *); int buffer_get_char_ret(u_char *, Buffer *); void *buffer_get_bignum2_as_string_ret(Buffer *, u_int *); diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c index d1d77744cf5..5421e15215e 100644 --- a/usr.bin/ssh/channels.c +++ b/usr.bin/ssh/channels.c @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.c,v 1.331 2014/02/26 20:29:29 djm Exp $ */ +/* $OpenBSD: channels.c,v 1.332 2014/04/28 03:09:18 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -2290,7 +2290,7 @@ void channel_input_data(int type, u_int32_t seq, void *ctxt) { int id; - char *data; + const u_char *data; u_int data_len, win_len; Channel *c; diff --git a/usr.bin/ssh/krl.c b/usr.bin/ssh/krl.c index 0a9e065a5c9..2e0d474683d 100644 --- a/usr.bin/ssh/krl.c +++ b/usr.bin/ssh/krl.c @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $OpenBSD: krl.c,v 1.14 2014/01/31 16:39:19 tedu Exp $ */ +/* $OpenBSD: krl.c,v 1.15 2014/04/28 03:09:18 djm Exp $ */ #include #include @@ -751,7 +751,8 @@ static int parse_revoked_certs(Buffer *buf, struct ssh_krl *krl) { int ret = -1, nbits; - u_char type, *blob; + u_char type; + const u_char *blob; u_int blen; Buffer subsect; u_int64_t serial, serial_lo, serial_hi; @@ -885,7 +886,8 @@ ssh_krl_from_blob(Buffer *buf, struct ssh_krl **krlp, char timestamp[64]; int ret = -1, r, sig_seen; Key *key = NULL, **ca_used = NULL; - u_char type, *blob, *rdata = NULL; + u_char type, *rdata = NULL; + const u_char *blob; u_int i, j, sig_off, sects_off, rlen, blen, format_version, nca_used; nca_used = 0; diff --git a/usr.bin/ssh/mux.c b/usr.bin/ssh/mux.c index fdd34333c2f..7df32df2425 100644 --- a/usr.bin/ssh/mux.c +++ b/usr.bin/ssh/mux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mux.c,v 1.44 2013/07/12 00:19:58 djm Exp $ */ +/* $OpenBSD: mux.c,v 1.45 2014/04/28 03:09:18 djm Exp $ */ /* * Copyright (c) 2002-2008 Damien Miller * @@ -997,7 +997,7 @@ mux_master_read_cb(Channel *c) { struct mux_master_state *state = (struct mux_master_state *)c->mux_ctx; Buffer in, out; - void *ptr; + const u_char *ptr; u_int type, rid, have, i; int ret = -1; @@ -1409,7 +1409,7 @@ mux_client_read_packet(int fd, Buffer *m) { Buffer queue; u_int need, have; - void *ptr; + const u_char *ptr; int oerrno; buffer_init(&queue); diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c index b0f6d9516fa..fae025c9e96 100644 --- a/usr.bin/ssh/packet.c +++ b/usr.bin/ssh/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.193 2014/04/01 05:32:57 djm Exp $ */ +/* $OpenBSD: packet.c,v 1.194 2014/04/28 03:09:18 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1604,7 +1604,7 @@ packet_get_string(u_int *length_ptr) return buffer_get_string(&active_state->incoming_packet, length_ptr); } -void * +const void * packet_get_string_ptr(u_int *length_ptr) { return buffer_get_string_ptr(&active_state->incoming_packet, length_ptr); diff --git a/usr.bin/ssh/packet.h b/usr.bin/ssh/packet.h index 9388140891a..5beb1677c8e 100644 --- a/usr.bin/ssh/packet.h +++ b/usr.bin/ssh/packet.h @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.h,v 1.59 2013/07/12 00:19:59 djm Exp $ */ +/* $OpenBSD: packet.h,v 1.60 2014/04/28 03:09:18 djm Exp $ */ /* * Author: Tatu Ylonen @@ -64,7 +64,7 @@ void packet_get_ecpoint(const EC_GROUP *, EC_POINT *); void *packet_get_raw(u_int *length_ptr); void *packet_get_string(u_int *length_ptr); char *packet_get_cstring(u_int *length_ptr); -void *packet_get_string_ptr(u_int *length_ptr); +const void *packet_get_string_ptr(u_int *length_ptr); void packet_disconnect(const char *fmt,...) __attribute__((noreturn)) __attribute__((format(printf, 1, 2))); void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c index ad27fcda54c..acb6f0d5cca 100644 --- a/usr.bin/ssh/ssh-keygen.c +++ b/usr.bin/ssh/ssh-keygen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keygen.c,v 1.244 2014/04/20 09:24:26 logan Exp $ */ +/* $OpenBSD: ssh-keygen.c,v 1.245 2014/04/28 03:09:18 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1994 Tatu Ylonen , Espoo, Finland @@ -1805,8 +1805,8 @@ add_cert_option(char *opt) static void show_options(const Buffer *optbuf, int v00, int in_critical) { - char *name; - u_char *data; + char *name, *arg; + const u_char *data; u_int dlen; Buffer options, option; @@ -1829,9 +1829,9 @@ show_options(const Buffer *optbuf, int v00, int in_critical) else if ((v00 || in_critical) && (strcmp(name, "force-command") == 0 || strcmp(name, "source-address") == 0)) { - data = buffer_get_string(&option, NULL); - printf(" %s\n", data); - free(data); + arg = buffer_get_cstring(&option, NULL); + printf(" %s\n", arg); + free(arg); } else { printf(" UNKNOWN OPTION (len %u)\n", buffer_len(&option)); -- 2.20.1