diff options
author | Thomas Haller <thaller@redhat.com> | 2019-06-19 15:17:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-06-19 15:30:55 +0200 |
commit | 637c785f4eaeac3f4804aedd765bde0629742285 (patch) | |
tree | 200701f83781b0088d1a345ddd221fa9a0ff5a86 /shared | |
parent | 4dce38c37f5fb116b50a6545b483ef628d6fceb6 (diff) | |
download | NetworkManager-637c785f4eaeac3f4804aedd765bde0629742285.tar.gz |
shared: fix nm_utils_bin2hexstr_full() for buffers of length zero
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index c8b0eef84e..49037ed7b4 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -2906,10 +2906,13 @@ nm_utils_memeqzero (gconstpointer data, gsize length) * be returned and must be freed by the caller. * If not %NULL, the buffer must already be preallocated and contain * at least (@length*2+1) or (@length*3) bytes, depending on the delimiter. + * If @length is zero, then of course at least one byte will be allocated + * or @out (if given) must contain at least room for the trailing NUL byte. * * Returns: the binary value converted to a hex string. If @out is given, * this always returns @out. If @out is %NULL, a newly allocated string - * is returned. + * is returned. This never returns %NULL, for buffers of length zero + * an empty string is returend. */ char * nm_utils_bin2hexstr_full (gconstpointer addr, @@ -2925,9 +2928,11 @@ nm_utils_bin2hexstr_full (gconstpointer addr, if (out) out0 = out; else { - out0 = out = g_new (char, delimiter == '\0' - ? length * 2 + 1 - : length * 3); + out0 = out = g_new (char, length == 0 + ? 1u + : ( delimiter == '\0' + ? length * 2u + 1u + : length * 3u)); } /* @out must contain at least @length*3 bytes if @delimiter is set, |