diff options
author | Thomas Haller <thaller@redhat.com> | 2021-05-11 22:58:51 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-05-12 09:38:15 +0200 |
commit | 77fb782060495121a34ff67b81d33aa3ea27ea71 (patch) | |
tree | 2855ea1b502836950d1c93d36f89370439f82a03 | |
parent | 4bc9c59c074a300de887a6398b8b1ade5b01419c (diff) | |
download | NetworkManager-77fb782060495121a34ff67b81d33aa3ea27ea71.tar.gz |
glib-aux: avoid potential undefined behavior for nm_str_buf_append_printf()
The string buffer may be empty and _priv_str still %NULL. Doing
pointer arithmetic with a %NULL pointer is undefined behavior.
Avoid that.
It's probably not an issue, because it results in computing &(((char *) NULL)[0],
and then g_vsnprintf() would not even inspect the pointer (so it doesn't
matter whether the computed pointer is bogus). But still, there is
undefined behavior involved.
-rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index cf9ba6f993..26856cd1ee 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -5555,7 +5555,10 @@ nm_str_buf_append_printf(NMStrBuf *strbuf, const char *format, ...) nm_assert(available < G_MAXULONG); va_start(args, format); - l = g_vsnprintf(&strbuf->_priv_str[strbuf->_priv_len], available, format, args); + l = g_vsnprintf(strbuf->_priv_str ? &strbuf->_priv_str[strbuf->_priv_len] : NULL, + available, + format, + args); va_end(args); nm_assert(l >= 0); |