Bug 1057600 - do not replace trailing \0 with spaces
Summary: do not replace trailing \0 with spaces
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: procps-ng
Version: 19
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jaromír Cápík
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-01-24 12:41 UTC by Michal Hlavinka
Modified: 2016-02-01 01:59 UTC (History)
2 users (show)

Fixed In Version: procps-ng-3.3.8-11.fc19
Clone Of:
Environment:
Last Closed: 2014-01-28 04:42:51 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Michal Hlavinka 2014-01-24 12:41:00 UTC
Description of problem:
ps reads cmdline from /proc/*/cmdline
This file contains list of arguments separated with \0. ps rewrites all \0 with space, so it can use it and print it out as one string. 
This behaviour breaks ksh shell - in some special cases, ksh does not exec new script, but executes it within itself and just rewrites argv and zeroes out the rest. Because ps replaces even trailing zeroes with spaces, ps gives odd results. 
For example instead of
"./a foo" 
it prints 
"./a foo              "

The problem lies in readproc.c:read_unvectored(...)
    if(n){
        int i=n;
        while(i--)
            if(dst[i]=='\n' || dst[i]=='\0') dst[i]=sep;
        if(dst[n-1]==' ') dst[n-1]='\0';
    }
    dst[n] = '\0';

before the rewrite while loop, it should skip trailing zeroes:
while(i && dst[i-1]=='\0') --i;


Version-Release number of selected component (if applicable):
1:procps-ng-3.3.8-10.fc19

How reproducible:
always

Steps to Reproduce:
################### cut here #########################
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int i;
  char *p;
  for(i=1;i<argc;++i)
  {
    p=argv[i];
    while(*p) *p++='\0';
  }
  printf("%d\n",getpid());
  sleep(99);
  return 0;
}
################### cut here #########################
1) gcc -o reproducer reproducer.c
2) ,/reproducer foo bar baz
<PID>
3) echo "'$(ps -p <PID> ho args)'"

Actual results:
'./reproducer            '

Expected results:
'./reproducer'

Additional info:

Comment 1 Jaromír Cápík 2014-01-24 14:38:55 UTC
Ahoj Michale.

That sounds reasonable. Going to test and commit upstream if the change is ok.

Thanks,
Jaromir.

Comment 2 Jaromír Cápík 2014-01-24 17:57:18 UTC
Fixed in all currently supported Fedora releases.

Comment 3 Fedora Update System 2014-01-24 18:01:46 UTC
procps-ng-3.3.8-15.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/procps-ng-3.3.8-15.fc20

Comment 4 Fedora Update System 2014-01-24 18:02:01 UTC
procps-ng-3.3.8-11.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/procps-ng-3.3.8-11.fc19

Comment 5 Fedora Update System 2014-01-25 13:54:57 UTC
Package procps-ng-3.3.8-15.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing procps-ng-3.3.8-15.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-1523/procps-ng-3.3.8-15.fc20
then log in and leave karma (feedback).

Comment 6 Fedora Update System 2014-01-28 04:42:51 UTC
procps-ng-3.3.8-15.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 7 Fedora Update System 2014-02-15 06:56:07 UTC
procps-ng-3.3.8-11.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.


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