shared: fix string truncation in nm_str_buf_append_printf()

If g_vsnprintf() returns that it wants to write 5 characters, it
really needs space for 5+1 characters. If we have 5 characters
available, it would have written "0123\0", which leaves the buffer
broken.

Fixes: eda47170ed ('shared: add NMStrBuf util')
This commit is contained in:
Thomas Haller 2020-06-21 12:38:45 +02:00
parent 83c79bc7a8
commit fd34fe50a2
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -4871,7 +4871,7 @@ nm_str_buf_append_printf (NMStrBuf *strbuf,
nm_assert (l >= 0);
nm_assert (l < G_MAXINT);
if ((gsize) l > available) {
if ((gsize) l >= available) {
gsize l2 = ((gsize) l) + 1u;
nm_str_buf_maybe_expand (strbuf, l2, FALSE);