linux/tools/net/sunrpc/xdrgen/tests/bad-version-number-negative.x
Chuck Lever 1663ea5b24 xdrgen: Reject out-of-range program, version, and procedure numbers
RFC 5531 assigns only unsigned constants to program, version, and
procedure numbers (Section 12.3) and encodes each as an unsigned
32-bit integer (Section 9), so a valid number falls within
[0, 2**32 - 1]. RFC 4506 Section 6.2 permits a signed decimal constant
for XDR constants in general and sets no ceiling on magnitude, so the
grammar accepts an out-of-range value without complaint. It reaches
generated code -- a negative procedure number emerges as an enumerator
such as "FOO = -5", valid C that compiles cleanly even though the wire
field is an unsigned 32-bit integer. Thus the xdrgen front end is the
only place that can reject the malformed value.

Extend the semantic checks to require each program, version, and
procedure number to fall within [0, 2**32 - 1].

Link: https://patch.msgid.link/20260712203451.124902-6-cel@kernel.org
Signed-off-by: Chuck Lever <cel@kernel.org>
2026-08-10 09:54:35 -04:00

20 lines
578 B
Plaintext

/*
* NEGATIVE TEST CASE -- xdrgen must REJECT this specification.
*
* RFC 5531 assigns only unsigned constants to program, version, and
* procedure numbers (Section 12.3). This spec gives the version a
* negative number, which the front end must reject.
*
* Expected diagnostic:
* negative version number -1 in program 'BADPROG'
*
* The tests directory has no automated runner; exercise by hand:
* ./xdrgen definitions tests/bad-version-number-negative.x (must fail)
*/
program BADPROG {
version BADVERS {
void BADPROC_NULL(void) = 0;
} = -1;
} = 100000;