summaryrefslogtreecommitdiffstats
path: root/text-utils/colcrt.c
diff options
context:
space:
mode:
authorSami Kerola2016-04-02 17:58:14 +0200
committerKarel Zak2016-04-13 12:29:16 +0200
commit962a7dc3b0372d718e1686a2d5734cbde4713cab (patch)
tree953916031b9311d022ab2d60814d8beb7dfe20c8 /text-utils/colcrt.c
parentlibmount: try absolute target before canonicalize (diff)
downloadkernel-qcow2-util-linux-962a7dc3b0372d718e1686a2d5734cbde4713cab.tar.gz
kernel-qcow2-util-linux-962a7dc3b0372d718e1686a2d5734cbde4713cab.tar.xz
kernel-qcow2-util-linux-962a7dc3b0372d718e1686a2d5734cbde4713cab.zip
colcrt: avoid the command getting hung [afl]
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>
Diffstat (limited to 'text-utils/colcrt.c')
-rw-r--r--text-utils/colcrt.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c
index abe3a0768..62f84251a 100644
--- a/text-utils/colcrt.c
+++ b/text-utils/colcrt.c
@@ -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