]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: interpret zero width for pending data as error
authorKarel Zak <kzak@redhat.com>
Thu, 15 Feb 2018 10:58:41 +0000 (11:58 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 15 Feb 2018 10:58:41 +0000 (11:58 +0100)
The command

 $ column -t -W2 -c11 <<< "cat dog bird"

causes finite loop, because there is no minimal column width (missing
header). The print functions should be robust enough to return -EINVAL
when nonsense is requested.

Addresses: https://github.com/karelzak/util-linux/pull/577
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/table_print.c

index 5606d23dee314a07c46305452321fa582eb2e907..b0b5b6c81f6660ed9fe7510a571abdf308cf083b 100644 (file)
@@ -387,6 +387,8 @@ static int print_pending_data(
 
        if (!cl->pending_data)
                return 0;
+       if (!width)
+               return -EINVAL;
 
        DBG(COL, ul_debugobj(cl, "printing pending data"));
 
@@ -405,7 +407,8 @@ static int print_pending_data(
        if (bytes == (size_t) -1)
                goto err;
 
-       step_pending_data(cl, bytes);
+       if (bytes)
+               step_pending_data(cl, bytes);
 
        if (color)
                fputs(color, tb->out);