From 3b4b0f01ecdc8b24cb10d871f200abb26bef1548 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Tue, 22 Apr 2014 23:00:06 +0200 Subject: buffer: add a hidden canary to detect format errors Reviewed-by: Andreas Schneider --- include/libssh/buffer.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h index 942089f0..a3e093c2 100644 --- a/include/libssh/buffer.h +++ b/include/libssh/buffer.h @@ -38,6 +38,8 @@ struct ssh_buffer_struct { uint32_t pos; }; +#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3) + LIBSSH_API void ssh_buffer_free(ssh_buffer buffer); LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer); LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer); @@ -49,9 +51,12 @@ int buffer_add_u32(ssh_buffer buffer, uint32_t data); int buffer_add_u64(ssh_buffer buffer, uint64_t data); int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len); int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer, const char *format, va_list ap); -int ssh_buffer_pack(struct ssh_buffer_struct *buffer, const char *format, ...); +int _ssh_buffer_pack(struct ssh_buffer_struct *buffer, const char *format, ...); +#define ssh_buffer_pack(buffer, format, ...) _ssh_buffer_pack((buffer),(format), __VA_ARGS__, SSH_BUFFER_PACK_END) int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer, const char *format, va_list ap); -int ssh_buffer_unpack(struct ssh_buffer_struct *buffer, const char *format, ...); +int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer, const char *format, ...); +#define ssh_buffer_unpack(buffer, format, ...) _ssh_buffer_unpack((buffer),(format), __VA_ARGS__, SSH_BUFFER_PACK_END) + int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len); int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source); int ssh_buffer_reinit(ssh_buffer buffer); -- cgit