util-linux/text-utils
Mike Frysinger 45b1087e74 pg: command enters infinite loop
In a multibyte locale such as en_GB.UTF-8, the pg command cannot handle files
containing a form feed character (ASCII 0x0c) at the start of a line. The
program enters an infinite loop.

I've traced the problem to the function endline_for_mb in file pg.c. The code
assumes that the libc function wcwidth will return a nonnegative value, which
is not true for a form feed character. wcwidth returns -1 and the unsigned
variable "pos" goes into underflow.

I'll attach a patch which tests whether the character is printable before
calling wcwidth. If not, it uses instead the width of the constant L'?' which
is later used to replace nonprintable characters. I trust that we can assume
printability of this constant :-)

Steps to Reproduce:
1. Select a multibyte locale (tested with en_GB.UTF-8)
2. Create a file with a form feed character (0x0c) at the start of a line.
3. Try to display this file using the pg command.

Reported-by: Mark Calderbank <m.calderbank@iname.com>
Reported-by: Mike Frysinger <vapier@gentoo.org>
Addresses: https://bugs.gentoo.org/297717
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-01-04 09:49:23 +01:00
..
.gitignore build-sys: ignore a bunch of generated files, mostly binaries 2008-04-14 14:08:00 +02:00
LICENSE.pg Imported from util-linux-2.11t tarball. 2006-12-07 00:25:58 +01:00
Makefile.am build-sys: rename to _execdir 2009-07-04 01:23:41 +02:00
README.clear Imported from util-linux-2.11b tarball. 2006-12-07 00:25:46 +01:00
README.col Imported from util-linux-2.2 tarball. 2006-12-07 00:25:32 +01:00
README.pg Imported from util-linux-2.11t tarball. 2006-12-07 00:25:58 +01:00
col.1 man pages: add "AVAILABILITY" section 2007-07-03 01:17:04 +02:00
col.c col: getwchar() errors shouldn't be hidden 2007-01-30 13:52:48 +01:00
colcrt.1 man pages: add "AVAILABILITY" section 2007-07-03 01:17:04 +02:00
colcrt.c replace bcopy,bzero,index and rindex 2009-08-17 11:15:59 +02:00
colrm.1 man pages: add "AVAILABILITY" section 2007-07-03 01:17:04 +02:00
colrm.c build-sys: nls/locale handling in util-linux-ng general 2007-09-19 23:15:21 +02:00
column.1 man pages: add "AVAILABILITY" section 2007-07-03 01:17:04 +02:00
column.c column: replace errs.h with libc err.h 2007-10-16 12:31:10 +02:00
conv.c Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
display.c hexdump: bug in hexdump when offset == file length 2009-12-01 13:23:05 +01:00
hexdump.1 hexdump.1: erroneous .Nm "" 2009-08-17 12:11:04 +02:00
hexdump.c Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
hexdump.h Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
hexsyntax.c Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
line.1 man pages: add "AVAILABILITY" section 2007-07-03 01:17:04 +02:00
line.c line: remove deprecated #ident directive 2009-11-20 14:19:03 +01:00
more.1 more.1: formatting 2009-08-17 12:11:12 +02:00
more.c po: fix msgid bugs 2009-12-10 13:04:41 +01:00
od.1 man pages: add "AVAILABILITY" section 2007-07-03 01:17:04 +02:00
odsyntax.c Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
parse.c replace bcopy,bzero,index and rindex 2009-08-17 11:15:59 +02:00
pg.1 pg.1: formatting 2009-08-17 12:11:12 +02:00
pg.c pg: command enters infinite loop 2010-01-04 09:49:23 +01:00
rev.1 remove CVS keywords 2008-07-28 11:10:08 +02:00
rev.c rev: use warn() in errs.h 2007-10-25 21:50:59 +02:00
tailf.1 tailf: inotify based reimplementation 2007-12-17 10:06:20 +01:00
tailf.c tailf: fix printf format 2009-11-23 10:14:56 +01:00
ul.1 ul.1: erroneous .SH instead of .Sh 2009-08-17 12:11:04 +02:00
ul.c replace bcopy,bzero,index and rindex 2009-08-17 11:15:59 +02:00

README.pg

README for the "pg" utility for Linux.

The "pg" utility is the historic System V equivalent to BSD's "more". This
is a free clone of it, and it is intended to conform to the SVID 4 as well
as the SUSv2 specification of this command.

Contrasting to the System V implementation, this one filters backspace
formatting sequences while searching, so you can comfortably search in nroff
output like manual pages.

This code uses routines as defined by SUSv2, so a glibc version of 2.1 or
higher is required on Linux. A curses implementation (like ncurses) must
be present as well.

If large files > 2GB are supported by the kernel and the C library, pg is
able to handle them.

Please send comments, bug-reports and especially bug-fixes to
<g-r@bigfoot.de> .

Gunnar Ritter
Freiburg i. Br.
Germany