Bug 1261738 - xdrstdio_create buffers do not output encoded values on ppc
Summary: xdrstdio_create buffers do not output encoded values on ppc
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libtirpc
Version: 7.2
Hardware: ppc64
OS: Linux
unspecified
high
Target Milestone: rc
: ---
Assignee: Steve Dickson
QA Contact: Zhi Li
URL:
Whiteboard:
: 1585658 (view as bug list)
Depends On: 1261596
Blocks: TRACKER-bugs-affecting-libguestfs 1484996 1585558
TreeView+ depends on / blocked
 
Reported: 2015-09-10 05:52 UTC by Murphy Zhou
Modified: 2018-10-30 11:48 UTC (History)
8 users (show)

Fixed In Version: libtirpc-0.2.4-0.12.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1261596
Environment:
Last Closed: 2018-10-30 11:48:24 UTC
Target Upstream Version:


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


Links
System ID Priority Status Summary Last Updated
Red Hat Bugzilla 1609208 'unspecified' 'CLOSED' 'broken for big endian arches' 2019-12-04 07:11:06 UTC
Red Hat Product Errata RHBA-2018:3312 None None None 2018-10-30 11:48:46 UTC

Internal Links: 1609208

Comment 2 Daniel Sands 2018-02-14 23:31:13 UTC
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-15 00:53:32 UTC
Created attachment 1396217 [details]
Fix for STDIO

Comment 4 Steve Dickson 2018-06-22 12:32:07 UTC
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 20:44:54 UTC
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 18:38:47 UTC
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

Comment 9 Richard W.M. Jones 2018-07-24 15:55:10 UTC
*** Bug 1585658 has been marked as a duplicate of this bug. ***

Comment 10 Zhi Li 2018-07-25 02:53:00 UTC
Verified with libtirpc-0.2.4-0.12.el7.ppc64:
~~~~~
[root@xxx]# uname -m
ppc64
[root@xxx]# rpm -q libtirpc
libtirpc-0.2.4-0.10.el7.ppc64
[root@xxx]# ./writer | ./reader
0 1 2 3 4 5 6 7 
>>>> [root@xxx]# ./writer-tirpc  | ./reader-tirpc
2942232856 2942232856 2942232856 2942232856 2942232856 2942232856 2942232856 2942232856 
>>>> [root@xxx]# ./writer-tirpc-header  | ./reader-tirpc-header
2318854424 2318854424 2318854424 2318854424 2318854424 2318854424 2318854424 2318854424 
[root@ibm-p730-06-lp4 ~]# rpm -e --nodeps libtirpc
[root@ibm-p730-06-lp4 ~]# rpm -q libtirpc
package libtirpc is not installed

###############
update libtirpc
###############
[root@xxx]# yum install libtirpc-0.2.4-0.12.el7.ppc64.rpm
....
<snip>
Installed:
  libtirpc.ppc64 0:0.2.4-0.12.el7                                                                                                                                                        
Complete!
[root@xxx]# rpm -q libtirpc
libtirpc-0.2.4-0.12.el7.ppc64
[root@xxx]# ./writer | ./reader
0 1 2 3 4 5 6 7 
>>>> [root@xxx]# ./writer-tirpc  | ./reader-tirpc
0 1 2 3 4 5 6 7 
>>>> [root@xxx]# ./writer-tirpc-header  | ./reader-tirpc-header
0 1 2 3 4 5 6 7

Comment 11 Zhi Li 2018-07-25 02:53:50 UTC
Moving to VERIFIED according to comment #10.

Comment 13 errata-xmlrpc 2018-10-30 11:48:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:3312


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