From: Arran Cudbard-Bell Date: Sun, 12 Feb 2017 18:22:34 +0000 (+0000) Subject: Return 0 from fr_radius_encode_pair if there are no attributes to encode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3dcae9173332396464cd6016f11e1effa61ebe17;p=thirdparty%2Ffreeradius-server.git Return 0 from fr_radius_encode_pair if there are no attributes to encode --- diff --git a/src/include/libradius.h b/src/include/libradius.h index 48f5ebc1f63..02916ce544f 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -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 diff --git a/src/lib/radius_encode.c b/src/lib/radius_encode.c index edabcadff3e..4e1ed4f0fc6 100644 --- a/src/lib/radius_encode.c +++ b/src/lib/radius_encode.c @@ -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);