mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 22:14:03 +02:00
xdrgen: Fix opaque and string encoders for unbounded members
The variable-length opaque and string encoder templates emit an
unconditional bound check, "if (value->NAME.len > MAXSIZE) return
false". XDR represents an unbounded specifier (opaque foo<>, string
foo<>) as a maxsize of 0, so for an unbounded member the check
degenerates to "len > 0" and the generated encoder refuses every
non-empty value.
The decoder does not share this defect. It delegates to
xdrgen_decode_opaque() and xdrgen_decode_string(), which treat a
maxlen of 0 as unbounded and skip the length check. The sibling
variable-length array templates already guard their bound check
with maxsize != "0".
Guard the bound check the same way in each affected template -- the
struct and pointer forms of both the opaque and string encoders --
so an unbounded member encodes a payload of any length while a
bounded member keeps its limit.
An explicit zero-length bound (foo<0>) parses to the same maxsize of
0 and so also skips the check; xdrgen does not distinguish it from
the unbounded form, matching the decoder and the array encoders.
Fixes: 4b132aacb0 ("tools: Add xdrgen")
Link: https://patch.msgid.link/20260712193122.116845-6-cel@kernel.org
Signed-off-by: Chuck Lever <cel@kernel.org>
This commit is contained in:
parent
c488328375
commit
daa52e3785
|
|
@ -2,7 +2,9 @@
|
|||
{% if annotate %}
|
||||
/* member {{ name }} (variable-length string) */
|
||||
{% endif %}
|
||||
{% if maxsize != "0" %}
|
||||
if (value->{{ name }}.len > {{ maxsize }})
|
||||
return false;
|
||||
{% endif %}
|
||||
if (xdr_stream_encode_opaque(xdr, value->{{ name }}.data, value->{{ name }}.len) < 0)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
{% if annotate %}
|
||||
/* member {{ name }} (variable-length opaque) */
|
||||
{% endif %}
|
||||
{% if maxsize != "0" %}
|
||||
if (value->{{ name }}.len > {{ maxsize }})
|
||||
return false;
|
||||
{% endif %}
|
||||
if (xdr_stream_encode_opaque(xdr, value->{{ name }}.data, value->{{ name }}.len) < 0)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
{% if annotate %}
|
||||
/* member {{ name }} (variable-length string) */
|
||||
{% endif %}
|
||||
{% if maxsize != "0" %}
|
||||
if (value->{{ name }}.len > {{ maxsize }})
|
||||
return false;
|
||||
{% endif %}
|
||||
if (xdr_stream_encode_opaque(xdr, value->{{ name }}.data, value->{{ name }}.len) < 0)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
{% if annotate %}
|
||||
/* member {{ name }} (variable-length opaque) */
|
||||
{% endif %}
|
||||
{% if maxsize != "0" %}
|
||||
if (value->{{ name }}.len > {{ maxsize }})
|
||||
return false;
|
||||
{% endif %}
|
||||
if (xdr_stream_encode_opaque(xdr, value->{{ name }}.data, value->{{ name }}.len) < 0)
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user