]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: avoid overflow in hextable buffer
authorDaniel P. Berrangé <berrange@redhat.com>
Mon, 20 Jan 2025 10:06:52 +0000 (10:06 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Mon, 20 Jan 2025 10:08:44 +0000 (10:08 +0000)
The assigned string is 17 chars long once the trailing nul is taken
into account. This triggers a warning with GCC 15

 src/util/virsystemd.c: In function ‘virSystemdEscapeName’:
 src/util/virsystemd.c:59:38: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
    59 |     static const char hextable[16] = "0123456789abcdef";
       |                                      ^~~~~~~~~~~~~~~~~~

Switch to a dynamically sized array as used in all the other places
we have a hextable array.

See also: https://gcc.gnu.org/PR115185
Reported-by: Yaakov Selkowitz <yselkowi@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virsystemd.c

index 5b772e29dde56807d77dfbe53ff6fa1d975a8667..d46e5f74fcab837c357756de78fe06c2858bb173 100644 (file)
@@ -56,7 +56,7 @@ struct _virSystemdActivationEntry {
 static void virSystemdEscapeName(virBuffer *buf,
                                  const char *name)
 {
-    static const char hextable[16] = "0123456789abcdef";
+    static const char hextable[] = "0123456789abcdef";
 
 #define ESCAPE(c) \
     do { \