diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-09-14 11:21:51 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2018-02-19 15:29:33 +0100 |
commit | bfed35761541fdf734ef5a0cce82d41314271ba5 (patch) | |
tree | 800adf74d3548b794214d2b06d68ab3ccd23d638 /lib/str.c | |
parent | 350d950b02791268fb2af8ba261a8c5747d1e543 (diff) | |
download | gnutls-bfed35761541fdf734ef5a0cce82d41314271ba5.tar.gz |
str: added helper functions to read prefixed data with 8 or 16-bit headers
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/str.c')
-rw-r--r-- | lib/str.c | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -828,6 +828,68 @@ _gnutls_buffer_pop_datum_prefix(gnutls_buffer_st * buf, } int +_gnutls_buffer_pop_datum_prefix16(gnutls_buffer_st * buf, + gnutls_datum_t * data) +{ + size_t size; + + if (buf->length < 2) { + gnutls_assert(); + return GNUTLS_E_PARSING_ERROR; + } + + size = _gnutls_read_uint16(buf->data); + + buf->data += 2; + buf->length -= 2; + + if (size > 0) { + size_t osize = size; + _gnutls_buffer_pop_datum(buf, data, size); + if (osize != data->size) { + gnutls_assert(); + return GNUTLS_E_PARSING_ERROR; + } + } else { + data->size = 0; + data->data = NULL; + } + + return 0; +} + +int +_gnutls_buffer_pop_datum_prefix8(gnutls_buffer_st * buf, + gnutls_datum_t * data) +{ + size_t size; + + if (buf->length < 1) { + gnutls_assert(); + return GNUTLS_E_PARSING_ERROR; + } + + size = buf->data[0]; + + buf->data++; + buf->length--; + + if (size > 0) { + size_t osize = size; + _gnutls_buffer_pop_datum(buf, data, size); + if (osize != data->size) { + gnutls_assert(); + return GNUTLS_E_PARSING_ERROR; + } + } else { + data->size = 0; + data->data = NULL; + } + + return 0; +} + +int _gnutls_buffer_append_data_prefix(gnutls_buffer_st * buf, int pfx_size, const void *data, size_t data_size) |