Skip to content

Commit 663ad8b

Browse files
committed
xdrgen: Fix return code checking in built-in XDR decoders
xdr_stream_encode_u32() returns XDR_UNIT on success. xdr_stream_decode_u32() returns zero or -EMSGSIZE, but never XDR_UNIT. Signed-off-by: Chuck Lever <[email protected]>
1 parent 4b132aa commit 663ad8b

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

include/linux/sunrpc/xdrgen/_builtins.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ xdrgen_decode_string(struct xdr_stream *xdr, string *ptr, u32 maxlen)
184184
__be32 *p;
185185
u32 len;
186186

187-
if (unlikely(xdr_stream_decode_u32(xdr, &len) != XDR_UNIT))
187+
if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
188188
return false;
189189
if (unlikely(maxlen && len > maxlen))
190190
return false;
@@ -215,7 +215,7 @@ xdrgen_decode_opaque(struct xdr_stream *xdr, opaque *ptr, u32 maxlen)
215215
__be32 *p;
216216
u32 len;
217217

218-
if (unlikely(xdr_stream_decode_u32(xdr, &len) != XDR_UNIT))
218+
if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
219219
return false;
220220
if (unlikely(maxlen && len > maxlen))
221221
return false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% if annotate %}
33
/* member {{ name }} (variable-length array) */
44
{% endif %}
5-
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) != XDR_UNIT)
5+
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) < 0)
66
return false;
77
{% if maxsize != "0" %}
88
if (ptr->{{ name }}.count > {{ maxsize }})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% if annotate %}
33
/* member {{ name }} (variable-length array) */
44
{% endif %}
5-
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) != XDR_UNIT)
5+
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) < 0)
66
return false;
77
{% if maxsize != "0" %}
88
if (ptr->{{ name }}.count > {{ maxsize }})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% if annotate %}
33
/* member {{ name }} (variable-length array) */
44
{% endif %}
5-
if (xdr_stream_decode_u32(xdr, &count) != XDR_UNIT)
5+
if (xdr_stream_decode_u32(xdr, &count) < 0)
66
return false;
77
if (count > {{ maxsize }})
88
return false;

0 commit comments

Comments
 (0)