[4.1] 2b85c12 Fix buffer underflow in _vsb_indent

Martin Blix Grydeland martin at varnish-software.com
Fri Sep 4 15:54:51 CEST 2015


commit 2b85c12f59265c51f1100e7ee0bed31d9ec0f8ab
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Fri Jul 31 15:49:37 2015 +0200

    Fix buffer underflow in _vsb_indent
    
    If s_indent > 0 and the buffer is empty, it would check s_buf[-1] for
    the '\n' character.
    
    Now it will indent either on previous character being a newline, or on
    empty buffer. This allows indenting also the very first line of a
    buffer.

diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index be147c2..eba639e 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -159,7 +159,7 @@ static void
 _vsb_indent(struct vsb *s)
 {
 	if (s->s_indent == 0 || s->s_error != 0 ||
-	    s->s_buf[s->s_len - 1] != '\n')
+	    (s->s_len > 0 && s->s_buf[s->s_len - 1] != '\n'))
 		return;
 	if (VSB_FREESPACE(s) <= s->s_indent &&
 	    VSB_extend(s, s->s_indent) < 0) {



More information about the varnish-commit mailing list