Bug 837621

Summary: sa -u cause Segmentation fault
Product: Red Hat Enterprise Linux 6 Reporter: Branislav Náter <bnater>
Component: psacctAssignee: Jaromír Cápík <jcapik>
Status: CLOSED CURRENTRELEASE QA Contact: Branislav Náter <bnater>
Severity: high Docs Contact:
Priority: high    
Version: 6.3CC: jpallich, ovasik
Target Milestone: rcKeywords: ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-11-14 05:41:11 EST Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 838998    

Description Branislav Náter 2012-07-04 08:09:56 EDT
Description of problem:
Running sa -u (print also user id) command cause Segmentation fault on i386 and s390x archs and produce incorect output on x86_64.

Version-Release number of selected component (if applicable):
psacct-6.3.2-63.el6_3.2

How reproducible:
always

Steps to Reproduce:
1. run "sa -u"
  
Actual results on different archs:
ppc64:  root       0.00 cpu       62k mem accton
x86_64: 13179672   0.00 cpu      979k mem accton
i386:   Segmentation fault
s390x:  Segmentation fault

Expected results:
root       0.00 cpu       62k mem accton

Additional info:
Output seems to be correct only on ppc64 architecture.

Traceback from i386:
(gdb) t a a bt

Thread 1 (process 14151):
#0  0x0804a3f4 in parse_acct_entries () at sa.c:1254
#1  0x0804abea in main (argc=2, argv=0xbffff364) at sa.c:585

Traceback from s390x:
(gdb) t a a bt

Thread 1 (process 8385):
#0  0x0000000080002b96 in parse_acct_entries () at sa.c:1254
#1  0x0000000080003312 in main (argc=<value optimized out>, argv=<value optimized out>) at sa.c:585
Comment 1 Jaromír Cápík 2012-07-10 10:00:21 EDT
rec->ac_uid is invalid for some reason ... needs a deeper analysis.
Comment 2 Jaromír Cápík 2012-07-10 10:19:56 EDT
Some parts of the code are really very strange ...

----------------------------------------------------

#if __BYTE_ORDER == __BIG_ENDIAN
# define ACCT_BYTEORDER 0x80        /* Accounting file is big endian.  */
#else
# define ACCT_BYTEORDER 0x00        /* Accounting file is little endian.  */
#endif

...
...

if ((version % ACCT_BYTEORDER) != 3) {

----------------------------------------------------

Anything modulo 0 must throw SIGFPE ... 

Fortunately the structure seems to be BIG ENDIAN even on LITTLE_ENDIAN architectures ... this has been redesigned in the new upstream version.
Comment 3 Jaromír Cápík 2012-07-10 10:30:49 EDT
It seems I've found the issue. The ac_uid field needs to be read from the rec_v3 variable in case of acct_v3 structures. The acct structure version detection is a bit nonsense, but it doesn't cause the trouble. It was a human factor ... a cut'n'paste issue. Gonna test that on other architectures.