summaryrefslogtreecommitdiff
path: root/lib/str.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-09-20 15:21:16 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2018-02-19 15:29:34 +0100
commit31956954a36973a56ddadbb6cae7d0cba7702ea5 (patch)
tree0edd3d205dab151bfce17eec1156d6603f7656cf /lib/str.c
parent732707b1faa412eef6081899e9a58a95e4c19f51 (diff)
downloadgnutls-31956954a36973a56ddadbb6cae7d0cba7702ea5.tar.gz
str: allow creating a read-only buffer
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/str.c')
-rw-r--r--lib/str.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/str.c b/lib/str.c
index 8400edc5d9..2f03ac9a62 100644
--- a/lib/str.c
+++ b/lib/str.c
@@ -123,6 +123,9 @@ gnutls_buffer_append_data(gnutls_buffer_t dest, const void *data,
size_t const tot_len = data_size + dest->length;
size_t const unused = MEMSUB(dest->data, dest->allocd);
+ if (unlikely(dest->data != NULL && dest->allocd == NULL))
+ return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
if (data_size == 0)
return 0;
@@ -160,6 +163,9 @@ gnutls_buffer_append_data(gnutls_buffer_t dest, const void *data,
int _gnutls_buffer_resize(gnutls_buffer_st * dest, size_t new_size)
{
+ if (unlikely(dest->data != NULL && dest->allocd == NULL))
+ return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
if (dest->max_length >= new_size) {
size_t unused = MEMSUB(dest->data, dest->allocd);
if (dest->max_length - unused <= new_size) {
@@ -209,7 +215,6 @@ void
_gnutls_buffer_pop_datum(gnutls_buffer_st * str, gnutls_datum_t * data,
size_t req_size)
{
-
if (str->length == 0) {
data->data = NULL;
data->size = 0;