Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 297717 - sys-apps/util-linux: pg command enters infinite loop
Summary: sys-apps/util-linux: pg command enters infinite loop
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-20 23:46 UTC by Mark Calderbank
Modified: 2010-01-05 13:24 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Proposed patch (pg.patch,397 bytes, patch)
2009-12-20 23:46 UTC, Mark Calderbank
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Calderbank 2009-12-20 23:46:05 UTC
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 :-)

The patch is against the latest release from kernel.org but it looks like the code hasn't changed since the last version in Gentoo.

Reproducible: Always

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.


Actual Results:  
pg command hangs.

Expected Results:  
pg command should display the file :-)
Comment 1 Mark Calderbank 2009-12-20 23:46:56 UTC
Created attachment 213620 [details, diff]
Proposed patch
Comment 2 SpanKY gentoo-dev 2010-01-05 00:07:42 UTC
upstream has taken your patch ... unless this is a critical issue for you, i'd prefer to just wait for the next release ;)
Comment 3 Mark Calderbank 2010-01-05 13:24:59 UTC
Thanks - next release is fine. I actually used pg by accident, thinking I was on a different Unix box that doesn't have less installed :-)