freebsd-src/lib/libc/xdr
Gleb Smirnoff 7f39f03c4d libc/xdr: remove bogus lseek(2) for xdr streams
Doing some debugging I noticed that applications using rpc(3) would often
make lseek(2) on a totally bogus file descriptor, that looks more like a
pointer.  So, what happens here is that xdrrec type xdr doesn't keep a
track of how many bytes were sent/received on the stream and tries to
obtain this number via lseek(2).  Then it adds/subtracts the offset in the
internal buffer from the obtained number.  This code originates from the
original Sun RPC import in 1994.  However, it was not a working code even
if Solaris would support lseek(2) on a socket, because it was passing not
the file descriptor, but a pointer to opaque data from upper RPC layer.
It could be that previously (before import to FreeBSD) code was correct,
but the Solaris 8 documentation says that lseek(2) on socket isn't
supported [1].  Maybe supported on older Solaris?

Anyway, this lseek(2) never worked and xdr_getpos() would always fail on
xdrrec object, until 8f55a568f6 in 2008 it was slightly fixed to
tolerate failure of lseek(2) and return a correct value within the small
internal buffer for XDR_ENCODE mode and a an incorrect (negative to
unsigned) result for XDR_DECODE.  It seems no consumer ever calls
xdr_getpos()/xdr_setpos() on this kind of descriptor when in XDR_DECODE
mode.

So, remove this lseek(2) and preserve operation within the small buffer
only. Supposedly fix the operation for XDR_DECODE mode.  Note that there
is no use and no test coverage for the XDR_DECODE.

Note that xdr(3) manual page already documents limitations for
xdr_getpos() and xdr_setpos() for the stream type objects.

[1] https://docs.oracle.com/cd/E19109-01/tsolaris8/835-8003/6ruu1b0or/index.html

Reviewed by:		asomers, markj
Differential Revision:	https://reviews.freebsd.org/D48205
2025-01-06 08:22:14 -08:00
..
Makefile.inc Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
Symbol.map libc: Remove empty comments in Symbol.map 2023-11-15 17:51:03 +00:00
xdr.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
xdr.c rpc: Fix the definition of xdr_void() 2024-10-30 19:27:18 +00:00
xdr_array.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
xdr_float.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
xdr_mem.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
xdr_rec.c libc/xdr: remove bogus lseek(2) for xdr streams 2025-01-06 08:22:14 -08:00
xdr_reference.c libc(xdr_reference.c): fix "referenced" spelling 2024-04-12 16:34:53 -06:00
xdr_sizeof.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
xdr_stdio.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00