Skip to content

Commit

Permalink
xdrgen: Fix return code checking in built-in XDR decoders
Browse files Browse the repository at this point in the history
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 <chuck.lever@oracle.com>
  • Loading branch information
chucklever committed Sep 20, 2024
1 parent 4b132aa commit 663ad8b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/linux/sunrpc/xdrgen/_builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ xdrgen_decode_string(struct xdr_stream *xdr, string *ptr, u32 maxlen)
__be32 *p;
u32 len;

if (unlikely(xdr_stream_decode_u32(xdr, &len) != XDR_UNIT))
if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
return false;
if (unlikely(maxlen && len > maxlen))
return false;
Expand Down Expand Up @@ -215,7 +215,7 @@ xdrgen_decode_opaque(struct xdr_stream *xdr, opaque *ptr, u32 maxlen)
__be32 *p;
u32 len;

if (unlikely(xdr_stream_decode_u32(xdr, &len) != XDR_UNIT))
if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
return false;
if (unlikely(maxlen && len > maxlen))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% if annotate %}
/* member {{ name }} (variable-length array) */
{% endif %}
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) != XDR_UNIT)
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) < 0)
return false;
{% if maxsize != "0" %}
if (ptr->{{ name }}.count > {{ maxsize }})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% if annotate %}
/* member {{ name }} (variable-length array) */
{% endif %}
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) != XDR_UNIT)
if (xdr_stream_decode_u32(xdr, &ptr->{{ name }}.count) < 0)
return false;
{% if maxsize != "0" %}
if (ptr->{{ name }}.count > {{ maxsize }})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% if annotate %}
/* member {{ name }} (variable-length array) */
{% endif %}
if (xdr_stream_decode_u32(xdr, &count) != XDR_UNIT)
if (xdr_stream_decode_u32(xdr, &count) < 0)
return false;
if (count > {{ maxsize }})
return false;
Expand Down

0 comments on commit 663ad8b

Please sign in to comment.