GNU bug report logs - #18621
[BUG] wc -c incorrectly counts bytes in /sys

Previous Next

Package: coreutils;

Reported by: George Shuklin <george.shuklin <at> gmail.com>

Date: Fri, 3 Oct 2014 15:13:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jim Meyering <jim <at> meyering.net>, Pádraig Brady <P <at> draigbrady.com>
Cc: 18621 <at> debbugs.gnu.org, George Shuklin <george.shuklin <at> gmail.com>
Subject: bug#18621: [BUG] wc -c incorrectly counts bytes in /sys
Date: Tue, 07 Oct 2014 00:09:24 -0700
[Message part 1 (text/plain, inline)]
Paul Eggert wrote:
> How about if we change usable_st_size to return false for these proc files

Attached is a better idea, I hope.  I audited the coreutils code to look for 
problematic uses of SEEK_END or st_size when reading files (I didn't look at 
writing; one can of worms at a time).

The attached patch still needs a changelog entry and test cases.  The basic idea 
is to not trust st_size when it's <= ST_BLKSIZE.  This fixes bugs in 'head', 
'od', 'split', 'tac', 'tail', and 'wc' when applied to input files in proc or 
sysfs file systems.

Here's an example bug fixed by this patch:

$ cat /sys/kernel/profiling
0
$ tail -2c /sys/kernel/profiling
$

This should be:

$ cat /sys/kernel/profiling
0
$ tail -2c /sys/kernel/profiling
0
$

[procsys.diff (text/plain, attachment)]

This bug report was last modified 10 years and 289 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.