protobuf-c 1.0.0 added a new 'allocator' field to ProtobufCBufferSimple
that controls memory allocation, which must be NULL in order to request
the default system allocator. Allocating ProtobufCBufferSimple objects
on the stack without zeroing the entire object can result in
protobuf-c's memory allocation functions dereferencing a garbage
pointer.
Note that the use of the zero initializer in this instance generates a
warning on some gcc versions:
dnstap.c: In function 'dt_pack':
dnstap.c:26:2: warning: missing braces around initializer [-Wmissing-braces]
ProtobufCBufferSimple sbuf = {0};
^
dnstap.c:26:2: warning: (near initialization for 'sbuf.base') [-Wmissing-braces]
This warning is spurious and was fixed recently:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=211289
---
src/dnstap/dnstap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/dnstap/dnstap.c b/src/dnstap/dnstap.c
index 41d42e7..cf3770c 100644
--- a/src/dnstap/dnstap.c
+++ b/src/dnstap/dnstap.c
@@ -23,7 +23,7 @@
uint8_t* dt_pack(const Dnstap__Dnstap *d, uint8_t **buf, size_t *sz)
{
- ProtobufCBufferSimple sbuf;
+ ProtobufCBufferSimple sbuf = {0};
sbuf.base.append = protobuf_c_buffer_simple_append;
sbuf.len = 0;
--
2.0.0