]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
colcrt: avoid the command getting hung [afl]
authorSami Kerola <kerolasa@iki.fi>
Sat, 2 Apr 2016 15:58:14 +0000 (16:58 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 15 Apr 2016 14:28:00 +0000 (16:28 +0200)
Some inputs make getwc(3) not to progress file descriptor and neither to
report EILSEQ.  Detect such situation and skip the bad input.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
tests/colcrt [new file with mode: 0755]
tests/expected/colcrt/regressions-hang1 [new file with mode: 0644]
tests/ts/colcrt/hang1 [new file with mode: 0644]
tests/ts/colcrt/regressions
text-utils/colcrt.c

diff --git a/tests/colcrt b/tests/colcrt
new file mode 100755 (executable)
index 0000000..d8c792b
Binary files /dev/null and b/tests/colcrt differ
diff --git a/tests/expected/colcrt/regressions-hang1 b/tests/expected/colcrt/regressions-hang1
new file mode 100644 (file)
index 0000000..cb16e46
--- /dev/null
@@ -0,0 +1,3 @@
+789:;<=>=>?IABUVNXYZ[ `abcdefgg !"#$%&'()*+,-./01234)*:,-./0123456789:;[=>?1234)*:,-./0123456789:;[=>?4456789:;<=>?IABUVN`abcdefg !"
+                     -
+return value: 0
diff --git a/tests/ts/colcrt/hang1 b/tests/ts/colcrt/hang1
new file mode 100644 (file)
index 0000000..d26259e
--- /dev/null
@@ -0,0 +1 @@
+789:;<=>=>?IABUVNXYZ[_`abcdefgg\1f !"#$%&'()*+,-./01234)*:,-./0123456789:;[=>?1234)*:,-./0123456789:;[=>?4456789:;<=>?IABUVN`abcdefg\1f !" $%&'()*+,-./0123z{|ΓΌ~e
\ No newline at end of file
index 067523f0894a6453215330550760c18a2c281662..2ab751c36d8fad9c994fc20c7b16b96a20337f87 100755 (executable)
@@ -23,12 +23,13 @@ ts_check_test_command "$TS_CMD_COLCRT"
 
 check_input_file() {
        ts_init_subtest ${1##*/}
-       $TS_CMD_COLCRT < $1 > $TS_OUTPUT 2>&1
+       timeout 2 $TS_CMD_COLCRT < $1 > $TS_OUTPUT 2>&1
        echo "return value: $?" >> $TS_OUTPUT
        ts_finalize_subtest
 }
 
 check_input_file "$TS_SELF/crash1"
 check_input_file "$TS_SELF/crash2"
+check_input_file "$TS_SELF/hang1"
 
 ts_finalize
index abe3a07683d1cfc8ec7a700c5718fe3f3df1b208..62f84251a0b4a59a8d7ee3f0ec6d4a8d2c5d6519 100644 (file)
@@ -152,6 +152,7 @@ static void colcrt(struct colcrt_control *ctl)
 {
        int col;
        wint_t c;
+       long old_pos;
 
        ctl->print_nl = 1;
        if (ctl->half_lines)
@@ -161,7 +162,13 @@ static void colcrt(struct colcrt_control *ctl)
                if (OUTPUT_COLS - 1 < col) {
                        output_lines(ctl, col);
                        errno = 0;
+                       old_pos = ftell(ctl->f);
                        while ((c = getwc(ctl->f)) != L'\n') {
+                               long new_pos = ftell(ctl->f);
+                               if (old_pos == new_pos)
+                                       fseek(ctl->f, 1, SEEK_CUR);
+                               else
+                                       old_pos = new_pos;
                                if (errno == 0 && c == WEOF)
                                        return;
                                else