]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG: buffers: don't return a negative value on buffer_total_space_res()
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2011 12:40:49 +0000 (13:40 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2011 20:00:46 +0000 (21:00 +0100)
In commit 4b517ca93aaaead8aa6143aa2836dc96417653c6 (MEDIUM: buffers:
add some new primitives and rework existing ones), we forgot to check
if buffer_max_len() < l.

No backport is needed.

include/proto/buffers.h

index b241a569fb7057775f581401caf183bdb7e0f2b6..0a2da34984cc94e99c7fa74d17f22c6be0753106 100644 (file)
@@ -103,11 +103,13 @@ static inline int buffer_total_space(const struct buffer *buf)
 }
 
 /* Return the maximum amount of bytes that can be written into the buffer,
- * excluding the reserved space, which is preserved.
+ * excluding the reserved space, which is preserved. 0 may be returned if
+ * the reserved space was already reached or used.
  */
 static inline int buffer_total_space_res(const struct buffer *buf)
 {
-       return buffer_max_len(buf) - buf->l;
+       int len = buffer_max_len(buf) - buf->l;
+       return len < 0 ? 0 : len;
 }
 
 /* Returns the number of contiguous bytes between <start> and <start>+<count>,