Bug 1261738 - xdrstdio_create buffers do not output encoded values on ppc
xdrstdio_create buffers do not output encoded values on ppc
Status: ON_QA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libtirpc (Show other bugs)
7.2
ppc64 Linux
unspecified Severity high
: rc
: ---
Assigned To: Steve Dickson
Zhi Li
: Patch
Depends On: 1261596
Blocks: 1484996
  Show dependency treegraph
 
Reported: 2015-09-10 01:52 EDT by Xiong Murphy Zhou
Modified: 2018-07-21 06:24 EDT (History)
7 users (show)

See Also:
Fixed In Version: libtirpc-0.2.4-0.12.el7
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1261596
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Fix for STDIO (950 bytes, patch)
2018-02-14 19:53 EST, Daniel Sands
no flags Details | Diff

  None (edit)
Comment 2 Daniel Sands 2018-02-14 18:31:13 EST
I have also encountered this bug.  It exists on PPC64.  The cause is that the xdr_putlong uses a long to store the converted value, then passes it to fwrite as a byte buffer.  Only the first 4 bytes are written, which is okay for a LE system after byteswapping, but writes all zeroes on BE systems.

in xdr_stdio.c:
115	xdrstdio_putlong(xdrs, lp)
116		XDR *xdrs;
117		const long *lp;
118	{
119		long mycopy = (long)htonl((u_int32_t)*lp);
120	
121		if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
122			return (FALSE);
123		return (TRUE);
124	}

It seems incorrect to make "mycopy" a long instead of a u_int32_t, especially considering the result on BE systems.
Comment 3 Daniel Sands 2018-02-14 19:53 EST
Created attachment 1396217 [details]
Fix for STDIO
Comment 4 Steve Dickson 2018-06-22 08:32:07 EDT
I'm not seeing this problem... 

ibm-p730-06-lp2$ arch
ppc64

ibm-p730-06-lp2$ rpm -q libtirpc-devel
libtirpc-devel-0.2.4-0.10.el7.ppc64

ibm-p730-06-lp2$ gcc -I/usr/include/tirpc reader.c -o reader-tirpc -ltirpc
ibm-p730-06-lp2$ gcc -I/usr/include/tirpc writer.c -o writer-tirpc -ltirpc

ibm-p730-06-lp2$ ./writer-tirpc | ./reader-tirpc
0 1 2 3 4 5 6 7 

ibm-p730-06-lp2$ ./writer | hexdump
0000000 0000 0000 0000 0000 0000 0000 0000 0001
0000010 0000 0000 0000 0002 0000 0000 0000 0003
0000020 0000 0000 0000 0004 0000 0000 0000 0005
0000030 0000 0000 0000 0006 0000 0000 0000 0007
0000040
ibm-p730-06-lp2$ ./writer-tirpc | hexdump
0000000 0000 0000 0000 0000 0000 0000 0000 0001
0000010 0000 0000 0000 0002 0000 0000 0000 0003
0000020 0000 0000 0000 0004 0000 0000 0000 0005
0000030 0000 0000 0000 0006 0000 0000 0000 0007
0000040
Comment 6 Daniel Sands 2018-06-22 16:44:54 EDT
Endianness makes the difference.  The code as is passes on LE systems, but fails on BE systems.

As explained above, it writes 4 bytes into an 8-byte temporary variable, then uses the pointer to the first 4 bytes in its write.  On LE systems, the first 4 bytes have the converted value.  On BE systems, the last 4 bytes have it and the first 4 are all zeroes.
Comment 7 Steve Dickson 2018-07-18 14:38:47 EDT
commit 145272c2b6d89a1c3a7de86a2cbef43880f1b61b
Author: Steve Dickson <steved@redhat.com>
Date:   Wed Jul 11 11:21:39 2018 -0400

    xdrstdio_create buffers do not output encoded values on ppc

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