Bug 134516 - ps truncates line to 2048 characters
Summary: ps truncates line to 2048 characters
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: procps
Version: 3.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Karel Zak
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks: 190430 203310
TreeView+ depends on / blocked
 
Reported: 2004-10-04 10:50 UTC by Bastien Nocera
Modified: 2018-10-19 19:15 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-01-08 22:57:01 UTC
Target Upstream Version:
Embargoed:


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


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2004:544 0 normal SHIPPED_LIVE Updated procps package 2004-12-21 05:00:00 UTC

Description Bastien Nocera 2004-10-04 10:50:01 UTC
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 10:52:46 UTC
Created attachment 104713 [details]
long-name.c

Comment 4 Karel Zak 2004-10-06 10:36:25 UTC
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 10:50:27 UTC
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 08:49:54 UTC
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 13:10:08 UTC
Looks good with 2.0.17-13.  Prepping for the next errata update.

Comment 8 Karel Zak 2004-12-16 14:48:33 UTC
Sorry, this going to RHEL3-U4 (and not to U5 as I expected).

Comment 9 John Flanagan 2004-12-21 19:09:46 UTC
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 14:38:53 UTC
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 15:17:20 UTC
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 15:35:06 UTC
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 15:36:15 UTC
Created attachment 128361 [details]
test_2047.sh

Comment 15 Bastien Nocera 2006-04-28 15:37:38 UTC
Created attachment 128362 [details]
test.sh

Comment 16 Keiichi Mori 2006-05-23 04:34:24 UTC
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 15:10:51 UTC
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 04:07:39 UTC
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 08:31:13 UTC
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 08:41:06 UTC
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 09:54:07 UTC
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 12:46:31 UTC
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 14:43:59 UTC
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.