]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mbsedit: remove usage of VLA
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 12 Sep 2023 22:20:02 +0000 (00:20 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Wed, 13 Sep 2023 06:37:02 +0000 (08:37 +0200)
Variable-length-arrays are susceptible to security issues, avoid them.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/mbsedit.c

index ecfa9f47915659e8880dfdbe007b207f6216c9d0..9cf4f0f8855fbe7486770f9399894b0a157d0987 100644 (file)
@@ -157,13 +157,14 @@ static size_t mbs_insert(char *str, wint_t c, size_t *ncells)
 
 #ifdef HAVE_WIDECHAR
        wchar_t wc = (wchar_t) c;
-       char in_buf[MB_CUR_MAX];
+       in = malloc(MB_CUR_MAX);
+       if (!in)
+               return -1;
 
-       n = wctomb(in_buf, wc);
+       n = wctomb(in, wc);
        if (n == (size_t) -1)
-               return n;
+               goto out;
        *ncells = wcwidth(wc);
-       in = in_buf;
 #else
        *ncells = 1;
        in = (char *) &c;
@@ -173,6 +174,10 @@ static size_t mbs_insert(char *str, wint_t c, size_t *ncells)
        memmove(str + n, str, bytes);
        memcpy(str, in, n);
        str[bytes + n] = '\0';
+out:
+#ifdef HAVE_WIDECHAR
+       free(in);
+#endif
        return n;
 }