]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: --separator segfaults
authorB Watson <yalhcru@gmail.com>
Tue, 14 Aug 2012 16:27:09 +0000 (18:27 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 14 Aug 2012 16:27:09 +0000 (18:27 +0200)
The --separator and --columns long options in util-linux-2.21.2 and in
a git clone from 5 minutes ago, don't work:

$ echo foobar | column -s x
foobar

$ echo foobar | column -c 10
foobar

$ echo foobar | column --separator=x
column: option '--separator' doesn't allow an argument

$ echo foobar | column --separator x
Segmentation fault

$ echo foobar | column --columns 10
column: bad columns width value: '(null)': Invalid argument

$ echo foobar | column --columns=10
column: option '--columns' doesn't allow an argument

Looks like a simple case of missing has_arg flag in the "struct
option" initialization for these two options. The patch just adds the
flag. I haven't done thorough testing of the patched code, but it
seems to work OK and it no longer segfaults or tries to dereference a
null pointer.

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

index aab9187ea507f311c9f4391bc0f016090cb6d83e..f33cc1447b94fbff7a6d5ce7f279022ea50e50e1 100644 (file)
@@ -121,9 +121,9 @@ int main(int argc, char **argv)
        {
                { "help",       0, 0, 'h' },
                { "version",    0, 0, 'V' },
-               { "columns",    0, 0, 'c' },
+               { "columns",    1, 0, 'c' },
                { "table",      0, 0, 't' },
-               { "separator",  0, 0, 's' },
+               { "separator",  1, 0, 's' },
                { "fillrows",   0, 0, 'x' },
                { NULL,         0, 0, 0 },
        };