]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
v4: Two minor changes to berval handling (#4427)
authorNick Porter <nick@portercomputing.co.uk>
Mon, 21 Mar 2022 12:29:20 +0000 (12:29 +0000)
committerGitHub <noreply@github.com>
Mon, 21 Mar 2022 12:29:20 +0000 (08:29 -0400)
* Allocate the correct length when extracting from bervals

* Add fr_ldap_berval_to_value_str_shallow()

src/lib/ldap/base.h
src/lib/ldap/util.c

index c7c5fcf9c109d22ac1dd7eafe090c77a9716b133..e63303a8a5fa40c7e4782538723abf3502f2df18 100644 (file)
@@ -556,6 +556,22 @@ static inline void fr_ldap_berval_to_value_shallow(fr_value_box_t *value, struct
        fr_value_box_memdup_shallow(value, NULL, (uint8_t *)berval->bv_val, berval->bv_len, true);
 }
 
+/** Inline function to copy pointer from a berval to a string value box
+ *
+ * Useful for printing contents of bervals known to contain strings in DEBUG output since
+ * they are not NULL terminated.
+ *
+ * @note This results in a shallow copy of the berval, so if the berval is freed
+ *     the value box becomes invalidated.
+ *
+ * @param[out] value   to write berval value to.
+ * @param[in] berval   top copy pointer / length from.
+ */
+static inline void fr_ldap_berval_to_value_str_shallow(fr_value_box_t *value, struct berval *berval)
+{
+       fr_value_box_bstrndup_shallow(value, NULL, berval->bv_val, berval->bv_len, true);
+}
+
 /** Compare two ldap trunk structures on connection URI / DN
  *
  * @param[in] one      first connection to compare.
index 23e16050e3188cc9eae4b94ce771afce15ac7eac..a59f3917f7b6cc2d452a9f748e7c3e2372275dc6 100644 (file)
@@ -375,7 +375,7 @@ uint8_t *fr_ldap_berval_to_bin(TALLOC_CTX *ctx, struct berval const *in)
 {
        uint8_t *out;
 
-       out = talloc_array(ctx, uint8_t, in->bv_len + 1);
+       out = talloc_array(ctx, uint8_t, in->bv_len);
        if (!out) return NULL;
 
        memcpy(out, in->bv_val, in->bv_len);