Bug 134516 - ps truncates line to 2048 characters
ps truncates line to 2048 characters
Status: CLOSED WONTFIX
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: procps (Show other bugs)
3.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: Karel Zak
Brian Brock
: Reopened
Depends On:
Blocks: 190430 203310
  Show dependency treegraph
 
Reported: 2004-10-04 06:50 EDT by Bastien Nocera
Modified: 2010-10-21 22:38 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-01-08 17:57:01 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
long-name.c (5.30 KB, text/plain)
2004-10-04 06:52 EDT, Bastien Nocera
no flags Details
Bugfix patch. (454 bytes, patch)
2004-10-22 04:49 EDT, Karel Zak
no flags Details | Diff
test_2047.sh (2.02 KB, text/plain)
2006-04-28 11:36 EDT, Bastien Nocera
no flags Details
test.sh (37 bytes, text/plain)
2006-04-28 11:37 EDT, Bastien Nocera
no flags Details
Testcase (616 bytes, application/octet-stream)
2006-07-03 00:07 EDT, Keiichi Mori
no flags Details

  None (edit)
Description Bastien Nocera 2004-10-04 06:50:01 EDT
Description of problem:
ps auxwwww (even with many more 'w's) will truncate the command-line
of the program to 2048 characters.
The real command-line is shown in /proc:
grep -a java /proc/*/cmdline

Version-Release number of selected component (if applicable):
procps-2.0.17-10

How reproducible:
Every time

Steps to Reproduce:
1. Attached a test case below
2. Compile and run it
3. Compare output in /proc and output of ps
Comment 1 Bastien Nocera 2004-10-04 06:52:46 EDT
Created attachment 104713 [details]
long-name.c
Comment 4 Karel Zak 2004-10-06 06:36:25 EDT
Hmm.. it's interesting:

$ ps -a -o command= | grep java | head -n 1 | tr -d "\n" | wc -c
1515
$ cat /proc/762/cmdline | wc -c
1515

$ uname -r
2.6.8-1.521

It's FC2 and long-name.c sets 3725 bytes to argv[0]. In this case a
problem is not in the procps.
Comment 5 Bastien Nocera 2004-10-06 06:50:27 EDT
Agreed, but the problem is in procps on a RHEL3 system, as the data is
correct is /proc.
Comment 6 Karel Zak 2004-10-22 04:49:54 EDT
Created attachment 105638 [details]
Bugfix patch.

This patch fix the problem with truncated output lines to 2048 characters in
procps 2.0.17. The problem will fixed in the next update (RHEL3-U5).
Comment 7 Jay Turner 2004-12-16 08:10:08 EST
Looks good with 2.0.17-13.  Prepping for the next errata update.
Comment 8 Karel Zak 2004-12-16 09:48:33 EST
Sorry, this going to RHEL3-U4 (and not to U5 as I expected).
Comment 9 John Flanagan 2004-12-21 14:09:46 EST
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2004-544.html
Comment 11 Bastien Nocera 2006-04-28 10:38:53 EDT
The problem still exists when the command-line is exactly 2047 characters
because of an off-by-one error in the procps-2.0.17-longcmd.patch patch.

in readproc.c:
        /* read whole file into a memory buffer, allocating as we go */
       while ((n = read(fd, buf, sizeof buf - 1)) > 0) {
               if (n < BUF_LEN)
                       end_of_file = 1;

BUF_LEN is *always* greater than n, as BUF_LEN is 2048, and we read up to 2048-1
characters.
Comment 12 Karel Zak 2006-04-28 11:17:20 EDT
Your code is without the patch. I see code:

        while ((n = read(fd, buf, sizeof buf - 1)) > 0) {
                if (n < (int) (sizeof buf - 1))
                        end_of_file = 1;

Comment 13 Bastien Nocera 2006-04-28 11:35:06 EDT
Seems I got that wrong, here are the 2 files for the test case.

$ ./test_2047.sh
<snip>

$ ps auxwwww
<snip>
bnocera    385  0.0  0.1  4640  992 pts/9    S+   16:40   0:00 [sh]
<snip>

Instead of the whole command-line.
Comment 14 Bastien Nocera 2006-04-28 11:36:15 EDT
Created attachment 128361 [details]
test_2047.sh
Comment 15 Bastien Nocera 2006-04-28 11:37:38 EDT
Created attachment 128362 [details]
test.sh
Comment 16 Keiichi Mori 2006-05-23 00:34:24 EDT
Fujitsu is asking what the current status on this.
Could engineer please update anything here ? And could we get the fix in RHEL3 ?
Comment 18 Karel Zak 2006-06-23 11:10:51 EDT
Bastien, 
http://people.redhat.com/kzak/procps/ps-test-truncates.tar.gz

$ tar zxvf ps-test-truncates.tar.gz
ps-test-truncates/
ps-test-truncates/run.sh
ps-test-truncates/ps_truncates.sh

$ cd ps-test-truncates/

$ ./run.sh
cmdline size (org=2029, new=2029) .... PASS

$ rpm -q procps
procps-2.0.17-13.7

(the latest version is 2.0.17-13.10)

Note: you can manually add "ps auxwwww" to the ps_truncates.sh srcipt and you
will see real output. I don't see there any problem.
Comment 20 Keiichi Mori 2006-07-03 00:07:39 EDT
Created attachment 131872 [details]
Testcase

Karel,

Please try this testcase under /tmp directory. You can see this issue with the
latest procps package.
[root@dhcp100 root]# tar zxvf ps-test-truncates.tar.gz -C /tmp/
ps-test-truncates/
ps-test-truncates/run.sh
ps-test-truncates/ps_truncates.sh
[root@dhcp100 root]# cd /tmp/ps-test-truncates/
[root@dhcp100 ps-test-truncates]# ./run.sh
cmdline size (org=1995, new=	 18) .... FAILED
===output===
[ps_truncates.sh]
============
[root@dhcp100 ps-test-truncates]# rpm -q procps
procps-2.0.17-13.10
Comment 21 Bastien Nocera 2006-07-10 04:31:13 EDT
Keiichi, I don't see this here.
# ./run.sh
cmdline size (org=1995, new=   1995) .... PASS
# rpm -q procps
procps-2.0.17-13.7
Comment 22 Keiichi Mori 2006-07-10 04:41:06 EDT
Bastien,

Where did you execute a testcase ? You need to run my testcase in comment#20
under /tmp/ps-test-truncates directory.

I have seen this issue both with procps-2.0.17-13.10 and procps-2.0.17-13.7.

[root@dhcp100 ps-test-truncates]# rpm -q procps
procps-2.0.17-13.7
[root@dhcp100 ps-test-truncates]# pwd
/tmp/ps-test-truncates
[root@dhcp100 ps-test-truncates]# ./run.sh
cmdline size (org=1995, new=     18) .... FAILED
===output===
[ps_truncates.sh]
============
[root@dhcp100 ps-test-truncates]# up2date --update

Fetching Obsoletes list for channel: rhel-i386-as-3...

Fetching Obsoletes list for channel: rhel-i386-as-3-extras...

Fetching Obsoletes list for channel: rhn-tools-rhel-3-as-i386...

Fetching Obsoletes list for channel: rhel-i386-as-3-fastrack...

Fetching rpm headers...
########################################

Name                                    Version        Rel
----------------------------------------------------------
kernel-smp-unsupported                  2.4.21         40.EL             i686
procps                                  2.0.17         13.10             i386
quagga                                  0.96.2         11.3E             i386
sendmail-doc                            8.12.11        4.RHEL3.6         i386


Testing package set / solving RPM inter-dependencies...
########################################
kernel-smp-unsupported-2.4. ########################## Done.
procps-2.0.17-13.10.i386.rp ########################## Done.
quagga-0.96.2-11.3E.i386.rp ########################## Done.
sendmail-doc-8.12.11-4.RHEL ########################## Done.
Preparing              ########################################### [100%]

Installing...
   1:procps                 ########################################### [100%]
   2:kernel-smp-unsupported ########################################### [100%]
   3:quagga                 ########################################### [100%]
   4:sendmail-doc           ########################################### [100%]
[root@dhcp100 ps-test-truncates]# ./run.sh
cmdline size (org=1995, new=     18) .... FAILED
===output===
[ps_truncates.sh]
============
[root@dhcp100 ps-test-truncates]# rpm -q procps
procps-2.0.17-13.10
Comment 23 Bastien Nocera 2006-07-10 05:54:07 EDT
Keiichi is right. You need to run the test in /tmp/ps-test-truncates
I could reproduce it without any problems. I guess the testcase needs to be
updated, and made a bit more solid.
Comment 24 Karel Zak 2006-07-10 08:46:31 EDT
I see the bug now. There is also bad condition for the while(). So the final
version of the patch must be:

-       while ((n = read(fd, buf, sizeof buf - 1)) > 0) {
-               if (n < BUF_LEN)
+       while ((n = read(fd, buf, sizeof buf - 1)) >= 0) {
+               if (n < (int) (sizeof buf - 1))


Note: this problem appears with procps-2.0.17-13.10 only when the size of
cmdline is exactly 2047 bytes.

Unofficial package (for your tests only) with bugfix:
http://people.redhat.com/kzak/procps/bz134516/procps-2.0.17-13.10.1.src.rpm

The same problem is in all procps packages (include the latest 3.2.7 version).
I'll send patch to upstream developer too.

Thanks for your enthusiasm!

Comment 25 Karel Zak 2006-07-10 10:43:59 EDT
Note: the test at http://people.redhat.com/kzak/procps/ps-test-truncates.tar.gz
has been updated and it's more stable now.

$ ./run.sh
 2050: PASS
 2049: PASS
 2048: PASS
 2047: FAILED for 2047 bytes in /proc/#/cmdline
===ps output procps-3.2.7-5===
[ps_truncates.sh]
==============================

Note You need to log in before you can comment on or make changes to this bug.