From: Karel Zak Date: Thu, 4 Aug 2022 08:10:19 +0000 (+0200) Subject: column: fix buffer overflow when -l specified X-Git-Tag: v2.39-rc1~564 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4aacf57da1e41643fa789d3ffe848d50029a62de;p=thirdparty%2Futil-linux.git column: fix buffer overflow when -l specified $ printf 'a b c\n1 2 3\n' | column -s : -t -o '-' -l2 a b c-ฤก 1 2 3- Signed-off-by: Karel Zak --- diff --git a/text-utils/column.c b/text-utils/column.c index a4ba24dcd3..3d068b08d2 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -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)