mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 17:20:11 +01:00
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.
This commit is contained in:
parent
4bc9c59c07
commit
77fb782060
1 changed files with 4 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue