diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2019-07-14 23:32:28 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2019-07-14 23:32:28 +0000 |
commit | b9fdba89a59951b5f4e2ee841ea9ac907f914de6 (patch) | |
tree | b9ee5f2521a8c3baae5c31ad2596c0b959e442e8 /usr.bin/ssh/sshbuf.h | |
parent | 4457a3921ba8448728d2a0525684e511016bc0f1 (diff) |
add some functions to perform random-access read/write operations
inside buffers with bounds checking. Intended to replace manual
pointer arithmetic wherever possible.
feedback and ok markus@
Diffstat (limited to 'usr.bin/ssh/sshbuf.h')
-rw-r--r-- | usr.bin/ssh/sshbuf.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/usr.bin/ssh/sshbuf.h b/usr.bin/ssh/sshbuf.h index c4858867261..48a301e2c26 100644 --- a/usr.bin/ssh/sshbuf.h +++ b/usr.bin/ssh/sshbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sshbuf.h,v 1.13 2019/01/21 09:54:11 djm Exp $ */ +/* $OpenBSD: sshbuf.h,v 1.14 2019/07/14 23:32:27 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -172,6 +172,26 @@ int sshbuf_put_u32(struct sshbuf *buf, u_int32_t val); int sshbuf_put_u16(struct sshbuf *buf, u_int16_t val); int sshbuf_put_u8(struct sshbuf *buf, u_char val); +/* Functions to peek at the contents of a buffer without modifying it. */ +int sshbuf_peek_u64(const struct sshbuf *buf, size_t offset, + u_int64_t *valp); +int sshbuf_peek_u32(const struct sshbuf *buf, size_t offset, + u_int32_t *valp); +int sshbuf_peek_u16(const struct sshbuf *buf, size_t offset, + u_int16_t *valp); +int sshbuf_peek_u8(const struct sshbuf *buf, size_t offset, + u_char *valp); + +/* + * Functions to poke values into an exisiting buffer (e.g. a length header + * to a packet). The destination bytes must already exist in the buffer. + */ +int sshbuf_poke_u64(struct sshbuf *buf, size_t offset, u_int64_t val); +int sshbuf_poke_u32(struct sshbuf *buf, size_t offset, u_int32_t val); +int sshbuf_poke_u16(struct sshbuf *buf, size_t offset, u_int16_t val); +int sshbuf_poke_u8(struct sshbuf *buf, size_t offset, u_char val); +int sshbuf_poke(struct sshbuf *buf, size_t offset, void *v, size_t len); + /* * Functions to extract or store SSH wire encoded strings (u32 len || data) * The "cstring" variants admit no \0 characters in the string contents. @@ -198,7 +218,6 @@ int sshbuf_get_string_direct(struct sshbuf *buf, const u_char **valp, /* Another variant: "peeks" into the buffer without modifying it */ int sshbuf_peek_string_direct(const struct sshbuf *buf, const u_char **valp, size_t *lenp); -/* XXX peek_u8 / peek_u32 */ /* * Functions to extract or store SSH wire encoded bignums and elliptic |