]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: fix buffer overflow when -l specified
authorKarel Zak <kzak@redhat.com>
Thu, 4 Aug 2022 08:10:19 +0000 (10:10 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 4 Aug 2022 08:20:57 +0000 (10:20 +0200)
$ printf 'a b c\n1 2 3\n' | column -s : -t -o '-' -l2
a b c-ฤก
1 2 3-

Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.c

index a4ba24dcd30db97ba6407746192fd224b649e8e4..3d068b08d2ef864e522d49e197fcc9c3162c1b85 100644 (file)
@@ -507,17 +507,23 @@ static void modify_table(struct column_control *ctl)
 static int add_line_to_table(struct column_control *ctl, wchar_t *wcs0)
 {
        wchar_t *wcdata, *sv = NULL, *wcs = wcs0;
-       size_t n = 0, nchars = 0;
+       size_t n = 0, nchars = 0, len;
        struct libscols_line *ln = NULL;
 
        if (!ctl->tab)
                init_table(ctl);
+
+       len = wcslen(wcs0);
+
        do {
                char *data;
 
-               if (ctl->maxncols && n + 1 == ctl->maxncols)
-                       wcdata = wcs0 + nchars;
-               else
+               if (ctl->maxncols && n + 1 == ctl->maxncols) {
+                       if (nchars < len)
+                               wcdata = wcs0 + nchars;
+                       else
+                               wcdata = NULL;
+               } else
                        wcdata = local_wcstok(ctl, wcs, &sv);
 
                if (!wcdata)