]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Return 0 from fr_radius_encode_pair if there are no attributes to encode
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 12 Feb 2017 18:22:34 +0000 (18:22 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 2 Mar 2017 20:03:56 +0000 (15:03 -0500)
src/include/libradius.h
src/lib/radius_encode.c

index 48f5ebc1f630163666beed44fb4478032efd9fb3..02916ce544f4d3ae969d9d25c685a02dab50353d 100644 (file)
@@ -256,7 +256,7 @@ int         fr_radius_encode_chap_password(uint8_t *output, RADIUS_PACKET *packet, int
 
 ssize_t                fr_radius_encode_value_hton(uint8_t *out, size_t outlen, VALUE_PAIR const *vp);
 
-int            fr_radius_encode_pair(uint8_t *out, size_t outlen, vp_cursor_t *cursor, void *encoder_ctx);
+ssize_t                fr_radius_encode_pair(uint8_t *out, size_t outlen, vp_cursor_t *cursor, void *encoder_ctx);
 
 /*
  *     radius_decode.c
index edabcadff3e399cc6aac4003f229ba58ef7e1c04..4e1ed4f0fc6e8d8a56235f25882bee16abf8aeb4 100644 (file)
@@ -1565,8 +1565,17 @@ static int encode_rfc_hdr(uint8_t *out, size_t outlen, fr_dict_attr_t const **tl
  * This is the main entry point into the encoder.  It sets up the encoder array
  * we use for tracking our TLV/VSA/EVS nesting and then calls the appropriate
  * dispatch function.
+ *
+ * @param[out] out             Where to write encoded data.
+ * @param[in] outlen           Length of the out buffer.
+ * @param[in] cursor           Specifying attribute to encode.
+ * @param[in] encoder_ctx      Additional data such as the shared secret to use.
+ * @return
+ *     - >0 The number of bytes written to out.
+ *     - 0 Nothing to encode (or attribute skipped).
+ *     - <0 an error occurred.
  */
-int fr_radius_encode_pair(uint8_t *out, size_t outlen, vp_cursor_t *cursor, void *encoder_ctx)
+ssize_t fr_radius_encode_pair(uint8_t *out, size_t outlen, vp_cursor_t *cursor, void *encoder_ctx)
 {
        VALUE_PAIR const *vp;
        int ret;
@@ -1576,8 +1585,9 @@ int fr_radius_encode_pair(uint8_t *out, size_t outlen, vp_cursor_t *cursor, void
        fr_dict_attr_t const *da = NULL;
 
        if (!cursor || !out || (outlen <= 2)) return -1;
+
        vp = first_encodable(cursor);
-       if (!vp) return -1;
+       if (!vp) return 0;
 
        VERIFY_VP(vp);