Skip to content

Commit 425364d

Browse files
committed
xdrgen: Fix code generated for counted arrays
When an XDR counted array has a maximum element count, xdrgen adds a bounds check to the encoder or decoder for that type. But in cases where the .x provides no maximum element count, such as struct notify4 { /* composed from notify_type4 or notify_deviceid_type4 */ bitmap4 notify_mask; notifylist4 notify_vals; }; struct CB_NOTIFY4args { stateid4 cna_stateid; nfs_fh4 cna_fh; notify4 cna_changes<>; }; xdrgen is supposed to omit that bounds check. Some of the Jinja2 templates handle that correctly, but a few are incorrect and leave the bounds check in place with a maximum of zero, which causes encoding/decoding of that type to fail unconditionally. Reported-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 1e7dbad commit 425364d

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

tools/net/sunrpc/xdrgen/templates/C/pointer/encoder/variable_length_array.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
{% if annotate %}
33
/* member {{ name }} (variable-length array) */
44
{% endif %}
5+
{% if maxsize != "0" %}
56
if (value->{{ name }}.count > {{ maxsize }})
67
return false;
8+
{% endif %}
79
if (xdr_stream_encode_u32(xdr, value->{{ name }}.count) != XDR_UNIT)
810
return false;
911
for (u32 i = 0; i < value->{{ name }}.count; i++)

tools/net/sunrpc/xdrgen/templates/C/struct/encoder/variable_length_array.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
{% if annotate %}
33
/* member {{ name }} (variable-length array) */
44
{% endif %}
5+
{% if maxsize != "0" %}
56
if (value->{{ name }}.count > {{ maxsize }})
67
return false;
8+
{% endif %}
79
if (xdr_stream_encode_u32(xdr, value->{{ name }}.count) != XDR_UNIT)
810
return false;
911
for (u32 i = 0; i < value->{{ name }}.count; i++)

tools/net/sunrpc/xdrgen/templates/C/union/decoder/variable_length_array.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
{% endif %}
55
if (xdr_stream_decode_u32(xdr, &count) < 0)
66
return false;
7+
{% if maxsize != "0" %}
78
if (count > {{ maxsize }})
89
return false;
10+
{% endif %}
911
for (u32 i = 0; i < count; i++) {
1012
if (xdrgen_decode_{{ type }}(xdr, &ptr->{{ name }}.items[i]) < 0)
1113
return false;

0 commit comments

Comments
 (0)