]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Tree/Trie: Check the end of buffer
authorPavel Tvrdik <pawel.tvrdik@gmail.com>
Sat, 1 Oct 2016 10:50:29 +0000 (12:50 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 11 Oct 2016 19:25:21 +0000 (21:25 +0200)
We set buffer->pos to buffer->end in function buffer_print() when
bvsnprintf() failed, so there would be uninitialized memory between
the old buffer->pos and the current buffer->pos.

filter/tree.c
filter/trie.c

index 328c7184b51a0a22e783c7ff0afc27f29754a529..1196e630f3a107f5d21cde59ad49e602f6cfcc18 100644 (file)
@@ -165,6 +165,9 @@ tree_format(struct f_tree *t, buffer *buf)
  
   tree_node_format(t, buf);
 
+  if (buf->pos == buf->end)
+    return;
+
   /* Undo last separator */
   if (buf->pos[-1] != '[')
     buf->pos -= 2;
index fba395d13fd28a43f4bfb6e06735057160de1a74..565ae82f6b27beb40cf7644f3fa73c43317e4caf 100644 (file)
@@ -300,6 +300,9 @@ trie_format(struct f_trie *t, buffer *buf)
     buffer_print(buf, "%I/%d, ", IPA_NONE, 0);
   trie_node_format(t->root, buf);
 
+  if (buf->pos == buf->end)
+    return;
+
   /* Undo last separator */
   if (buf->pos[-1] != '[')
     buf->pos -= 2;