From fd34fe50a2100ce5d9440047ec65f25097cb6a32 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Jun 2020 12:38:45 +0200 Subject: [PATCH] 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: eda47170ed2e ('shared: add NMStrBuf util') --- shared/nm-glib-aux/nm-shared-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index cb43182c41..39dfe6f473 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -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);