Cole Robinson 18af6f4e64 buf: Fix possible infinite loop in EscapeString, VSnprintf
The current code will go into an infinite loop if the printf generated
string is >= 1000, AND exactly 1 character smaller than the amount of free
space in the buffer. When this happens, we are dropped into the loop body,
but nothing will actually change, because count == (buf->size - buf->use - 1),
and virBufferGrow returns unchanged if count < (buf->size - buf->use)

Fix this by removing the '- 1' bit from 'size'. The *nprintf functions handle
the NULL byte for us anyways, so we shouldn't need to manually accommodate
for it.

Here's a bug where we are actually hitting this issue:
https://bugzilla.redhat.com/show_bug.cgi?id=602772

v2: Eric's improvements: while -> if (), remove extra va_list variable,
    make sure we report buffer error if snprintf fails

v3: Add tests/virbuftest which reproduces the infinite loop before this
    patch, works correctly after
2010-09-10 10:05:43 -04:00
..
2010-05-21 16:02:18 -06:00
2010-08-14 10:48:16 -06:00
2010-04-26 17:20:02 +02:00
2010-02-01 09:39:54 -05:00
2010-05-28 06:54:28 -06:00
2010-03-29 18:21:04 +02:00
2010-06-02 21:35:22 -04:00
2010-06-02 21:35:22 -04:00
2010-06-02 21:35:22 -04:00
2010-04-15 11:39:10 -06:00
2010-08-02 09:54:38 -04:00
2010-05-06 14:35:38 -06:00
2010-02-19 11:52:04 +01:00
2010-03-26 18:01:15 +00:00
2010-06-10 06:05:31 -06:00
2010-06-10 06:05:31 -06:00
2010-08-30 22:21:54 +02:00
2010-08-30 22:21:54 +02:00
2010-08-30 22:21:54 +02:00
2010-03-23 15:40:04 +01:00
2010-03-23 15:40:04 +01:00