]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xdrgen: Fix code generated for counted arrays
authorChuck Lever <chuck.lever@oracle.com>
Fri, 16 May 2025 13:37:12 +0000 (09:37 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Fri, 16 May 2025 14:58:48 +0000 (10:58 -0400)
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>
tools/net/sunrpc/xdrgen/templates/C/pointer/encoder/variable_length_array.j2
tools/net/sunrpc/xdrgen/templates/C/struct/encoder/variable_length_array.j2
tools/net/sunrpc/xdrgen/templates/C/union/decoder/variable_length_array.j2

index 0ec8660d621ab253e933431dce694d5595dc73d9..b21476629679831447b52b7923e56c554cac2d9c 100644 (file)
@@ -2,8 +2,10 @@
 {% if annotate %}
        /* member {{ name }} (variable-length array) */
 {% endif %}
+{% if maxsize != "0" %}
        if (value->{{ name }}.count > {{ maxsize }})
                return false;
+{% endif %}
        if (xdr_stream_encode_u32(xdr, value->{{ name }}.count) != XDR_UNIT)
                return false;
        for (u32 i = 0; i < value->{{ name }}.count; i++)
index 0ec8660d621ab253e933431dce694d5595dc73d9..b21476629679831447b52b7923e56c554cac2d9c 100644 (file)
@@ -2,8 +2,10 @@
 {% if annotate %}
        /* member {{ name }} (variable-length array) */
 {% endif %}
+{% if maxsize != "0" %}
        if (value->{{ name }}.count > {{ maxsize }})
                return false;
+{% endif %}
        if (xdr_stream_encode_u32(xdr, value->{{ name }}.count) != XDR_UNIT)
                return false;
        for (u32 i = 0; i < value->{{ name }}.count; i++)
index 51ad736d2530b7f172f7e818631509c492cb114d..53dfaf9cec68571f191e7995918413ae56734e60 100644 (file)
@@ -4,8 +4,10 @@
 {% endif %}
                if (xdr_stream_decode_u32(xdr, &count) < 0)
                        return false;
+{% if maxsize != "0" %}
                if (count > {{ maxsize }})
                        return false;
+{% endif %}
                for (u32 i = 0; i < count; i++) {
                        if (xdrgen_decode_{{ type }}(xdr, &ptr->{{ name }}.items[i]) < 0)
                                return false;