aboutsummaryrefslogtreecommitdiff
path: root/external/unbound/sldns/sbuffer.c
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-06-24 12:42:28 +0200
committerRiccardo Spagni <ric@spagni.net>2017-06-24 12:42:29 +0200
commit389cd6c466486e670e6f9cd74d2cfdf46f392340 (patch)
treec4b10fac237c407badc8300b2d6116fe6a1ce7cb /external/unbound/sldns/sbuffer.c
parentMerge pull request #2073 (diff)
parentUpgrade unbound library (diff)
downloadmonero-389cd6c466486e670e6f9cd74d2cfdf46f392340.tar.xz
Merge pull request #2089
a85b5759 Upgrade unbound library (Erik de Castro Lopo)
Diffstat (limited to '')
-rw-r--r--external/unbound/sldns/sbuffer.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/external/unbound/sldns/sbuffer.c b/external/unbound/sldns/sbuffer.c
index a7fe53aa0..a04b9b655 100644
--- a/external/unbound/sldns/sbuffer.c
+++ b/external/unbound/sldns/sbuffer.c
@@ -33,6 +33,7 @@ sldns_buffer_new(size_t capacity)
buffer->_position = 0;
buffer->_limit = buffer->_capacity = capacity;
buffer->_fixed = 0;
+ buffer->_vfixed = 0;
buffer->_status_err = 0;
sldns_buffer_invariant(buffer);
@@ -48,6 +49,7 @@ sldns_buffer_new_frm_data(sldns_buffer *buffer, void *data, size_t size)
buffer->_position = 0;
buffer->_limit = buffer->_capacity = size;
buffer->_fixed = 0;
+ buffer->_vfixed = 0;
buffer->_data = malloc(size);
if(!buffer->_data) {
buffer->_status_err = 1;
@@ -66,6 +68,17 @@ sldns_buffer_init_frm_data(sldns_buffer *buffer, void *data, size_t size)
buffer->_data = data;
buffer->_capacity = buffer->_limit = size;
buffer->_fixed = 1;
+ buffer->_vfixed = 0;
+}
+
+void
+sldns_buffer_init_vfixed_frm_data(sldns_buffer *buffer, void *data, size_t size)
+{
+ memset(buffer, 0, sizeof(*buffer));
+ buffer->_data = data;
+ buffer->_capacity = buffer->_limit = size;
+ buffer->_fixed = 1;
+ buffer->_vfixed = 1;
}
int
@@ -74,7 +87,7 @@ sldns_buffer_set_capacity(sldns_buffer *buffer, size_t capacity)
void *data;
sldns_buffer_invariant(buffer);
- assert(buffer->_position <= capacity);
+ assert(buffer->_position <= capacity && !buffer->_fixed);
data = (uint8_t *) realloc(buffer->_data, capacity);
if (!data) {
@@ -126,7 +139,7 @@ sldns_buffer_printf(sldns_buffer *buffer, const char *format, ...)
if (written == -1) {
buffer->_status_err = 1;
return -1;
- } else if ((size_t) written >= remaining) {
+ } else if (!buffer->_vfixed && (size_t) written >= remaining) {
if (!sldns_buffer_reserve(buffer, (size_t) written + 1)) {
buffer->_status_err = 1;
return -1;