/*
* Trim the final ", "
*/
- MEM(list = talloc_realloc_bstr(list, talloc_array_length(list) - 3));
+ MEM(list = talloc_realloc_bstr(NULL, list, talloc_array_length(list) - 3));
cf_log_err(cp, "Invalid value \"%s\". Expected one of %s", cf_pair_value(cp), list);
+ talloc_free(list);
+
return -1;
}
child_str = xlat_fmt_aprint(pool, child);
if (child_str) {
- n_out = talloc_buffer_append_buffer(out, child_str);
+ n_out = talloc_buffer_append_buffer(ctx, out, child_str);
if (!n_out) {
talloc_free(out);
talloc_free(pool);
/*
* Shrink the buffer
*/
- if ((node->xlat->buf_len > 0) && (slen > 0)) MEM(str = talloc_realloc_bstr(str, (size_t)slen));
+ if ((node->xlat->buf_len > 0) && (slen > 0)) {
+ MEM(str = talloc_realloc_bstr(ctx, str, (size_t)slen));
+ }
/*
* Fixup talloc lineage and assign the
/*
* Shrink the buffer to the right size
*/
- MEM(start = talloc_realloc_bstr(start, node->len));
+ MEM(start = talloc_realloc_bstr(ctx, start, node->len));
node->fmt = start;
return p - fmt;
}
ref_n = talloc_zero(dict->pool, fr_dict_attr_ref_t);
- ref_n->tlv.name = talloc_typed_strdup(ref, name);
+ ref_n->tlv.name = talloc_typed_strdup(ref_n, name);
if (!ref_n->tlv.name) {
talloc_free(ref_n);
fr_strerror_printf("Out of memory");
* ...and as pcre2_substitute just succeeded actual_len does not include \0.
*/
if (actual_len < (buff_len - 1)) {
- buff = talloc_realloc_bstr(buff, actual_len);
+ buff = talloc_realloc_bstr(ctx, buff, actual_len);
if (!buff) {
fr_strerror_printf("reallocing pcre2_substitute result buffer failed");
return -1;
* memory chunk type to char, which causes all kinds of issues with
* verifying VALUE_PAIRs.
*
- * @param[in] t The talloc context to hang the result off.
- * @param[in] p The string you want to duplicate.
+ * @param[in] ctx The talloc context to hang the result off.
+ * @param[in] p The string you want to duplicate.
* @return
* - Duplicated string.
* - NULL on error.
*/
-char *talloc_typed_strdup(void const *t, char const *p)
+char *talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
{
char *n;
- n = talloc_strdup(t, p);
+ n = talloc_strdup(ctx, p);
if (!n) return NULL;
talloc_set_type(n, char);
* memory chunk type to char, which causes all kinds of issues with
* verifying VALUE_PAIRs.
*
- * @param[in] t The talloc context to hang the result off.
- * @param[in] fmt The format string.
+ * @param[in] ctx The talloc context to hang the result off.
+ * @param[in] fmt The format string.
* @return
* - Formatted string.
* - NULL on error.
*/
-char *talloc_typed_asprintf(void const *t, char const *fmt, ...)
+char *talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt, ...)
{
char *n;
va_list ap;
va_start(ap, fmt);
- n = talloc_vasprintf(t, fmt, ap);
+ n = talloc_vasprintf(ctx, fmt, ap);
va_end(ap);
if (!n) return NULL;
talloc_set_type(n, char);
* memory chunk type to char, which causes all kinds of issues with
* verifying VALUE_PAIRs.
*
- * @param[in] t The talloc context to hang the result off.
- * @param[in] fmt The format string.
- * @param[in] ap varadic arguments.
+ * @param[in] ctx The talloc context to hang the result off.
+ * @param[in] fmt The format string.
+ * @param[in] ap varadic arguments.
* @return
* - Formatted string.
* - NULL on error.
*/
-char *talloc_typed_vasprintf(void const *t, char const *fmt, va_list ap)
+char *talloc_typed_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap)
{
char *n;
- n = talloc_vasprintf(t, fmt, ap);
+ n = talloc_vasprintf(ctx, fmt, ap);
if (!n) return NULL;
talloc_set_type(n, char);
/** Binary safe strndup function
*
- * @param[in] t he talloc context to allocate new buffer in.
+ * @param[in] ctx he talloc context to allocate new buffer in.
* @param[in] in String to dup, may contain embedded '\0'.
* @param[in] inlen Number of bytes to dup.
* @return duped string.
*/
-char *talloc_bstrndup(void const *t, char const *in, size_t inlen)
+char *talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
{
char *p;
- p = talloc_array(t, char, inlen + 1);
+ p = talloc_array(ctx, char, inlen + 1);
if (!p) return NULL;
/*
return p;
}
+/** Append a bstr to a bstr
+ *
+ * @param[in] ctx to allocated.
+ * @param[in] to string to append to.
+ * @param[in] from string to append from.
+ * @param[in] from_len Length of from.
+ * @return
+ * - Realloced buffer containing both to and from.
+ * - NULL on failure. To will still be valid.
+ */
+char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t from_len)
+{
+ char *n;
+ size_t to_len;
+
+ to_len = talloc_array_length(to);
+ if (to[to_len - 1] == '\0') to_len--; /* Inlen should be length of input string */
+
+ n = talloc_realloc_size(ctx, to, to_len + from_len + 1);
+ if (!n) return NULL;
+
+ memcpy(n + to_len, from, from_len);
+ n[to_len + from_len] = '\0';
+ talloc_set_type(n, char);
+
+ return n;
+}
+
/** Trim a bstr (char) buffer
*
* Reallocs to inlen + 1 and '\0' terminates the string buffer.
* - The realloced string on success. in then points to invalid memory.
* - NULL on failure. In will still be valid.
*/
-char *talloc_realloc_bstr(char *in, size_t inlen)
+char *talloc_realloc_bstr(TALLOC_CTX *ctx, char *in, size_t inlen)
{
char *n;
- n = talloc_realloc_size(talloc_parent(in), in, inlen + 1);
+ n = talloc_realloc_size(ctx, in, inlen + 1);
if (!n) return NULL;
n[inlen] = '\0';
/** Concatenate to + from
*
+ * @param[in] ctx to allocate realloced buffer in.
* @param[in] to talloc string buffer to append to.
* @param[in] from talloc string buffer to append.
* @return
* returns to may point to invalid memory and should
* not be used.
*/
-char *talloc_buffer_append_buffer(char *to, char const *from)
+char *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from)
{
size_t to_len, from_len, total_len;
char *out;
from_len = talloc_array_length(from);
total_len = to_len + (from_len - 1);
- out = talloc_realloc(talloc_parent(to), to, char, total_len);
+ out = talloc_realloc(ctx, to, char, total_len);
if (!out) return NULL;
memcpy(out + (to_len - 1), from, from_len);
/** Concatenate to + ...
*
+ * @param[in] ctx to allocate realloced buffer in.
* @param[in] to talloc string buffer to append to.
* @param[in] argc how many variadic arguments were passed.
* @param[in] ... talloc string buffer(s) to append.
* returns to may point to invalid memory and should
* not be used.
*/
-char *talloc_buffer_append_variadic_buffer(char *to, int argc, ...)
+char *talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc, ...)
{
va_list ap_val, ap_len;
int i;
return to;
}
- out = talloc_realloc(talloc_parent(to), to, char, total_len + 1);
+ out = talloc_realloc(ctx, to, char, total_len + 1);
if (!out) goto finish;
p = out + to_len;
TALLOC_CTX *talloc_page_aligned_pool(TALLOC_CTX *ctx, void **start, void **end, size_t size);
-char *talloc_typed_strdup(void const *t, char const *p);
+char *talloc_typed_strdup(TALLOC_CTX *ctx, char const *p);
-char *talloc_typed_asprintf(void const *t, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
+char *talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
-char *talloc_typed_vasprintf(void const *t, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0)) CC_HINT(nonnull (2));
+char *talloc_typed_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0)) CC_HINT(nonnull (2));
-char *talloc_bstrndup(void const *t, char const *in, size_t inlen);
+char *talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen);
-char *talloc_realloc_bstr(char *in, size_t inlen);
+char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t from_len);
-char *talloc_buffer_append_buffer(char *to, char const *from);
+char *talloc_realloc_bstr(TALLOC_CTX *ctx, char *in, size_t inlen);
-char *talloc_buffer_append_variadic_buffer(char *to, int argc, ...);
+char *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from);
+
+char *talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc, ...);
int talloc_memcmp_array(uint8_t const *a, uint8_t const *b);
(void) talloc_get_type_abort_const(src, char);
len = talloc_array_length(src);
- if ((len == 1) || (src[len - 1] != '\0')) {
+ if ((len == 0) || (src[len - 1] != '\0')) {
fr_strerror_printf("Input buffer not \\0 terminated");
return -1;
}
str = fr_value_box_asprint(pool, vb, quote);
if (!str) continue;
- new_aggr = talloc_buffer_append_variadic_buffer(aggr, 2, td, str);
+ new_aggr = talloc_buffer_append_variadic_buffer(ctx, aggr, 2, td, str);
if (unlikely(!new_aggr)) {
talloc_free(aggr);
talloc_free(pool);
}
thread->inst = inst;
- thread->name = talloc_typed_asprintf(inst, "proto_detail polling for files matching %s", inst->filename);
+ thread->name = talloc_typed_asprintf(thread, "proto_detail polling for files matching %s", inst->filename);
thread->vnode_fd = -1;
pthread_mutex_init(&thread->worker_mutex, NULL);
{
char *n;
- n = talloc_realloc_bstr(plaintext, plaintext_len);
+ n = talloc_realloc_bstr(ctx, plaintext, plaintext_len);
if (unlikely(!n)) {
REDEBUG("Failed shrinking plaintext buffer");
talloc_free(plaintext);
return 0;
}
-static ssize_t xlat_a(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
+static ssize_t xlat_a(TALLOC_CTX *ctx, char **out, size_t outlen,
void const *mod_inst, UNUSED void const *xlat_inst,
REQUEST *request, char const *fmt)
{
/* Used and thus impossible value from heap to designate incomplete */
memcpy(ubres, &mod_inst, sizeof(*ubres));
- fmt2 = talloc_typed_strdup(inst, fmt);
+ fmt2 = talloc_typed_strdup(ctx, fmt);
ub_resolve_async(inst->ub, fmt2, 1, 1, ubres, link_ubres, &async_id);
talloc_free(fmt2);
return -1;
}
-static ssize_t xlat_aaaa(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
+static ssize_t xlat_aaaa(TALLOC_CTX *ctx, char **out, size_t outlen,
void const *mod_inst, UNUSED void const *xlat_inst,
REQUEST *request, char const *fmt)
{
/* Used and thus impossible value from heap to designate incomplete */
memcpy(ubres, &mod_inst, sizeof(*ubres));
- fmt2 = talloc_typed_strdup(inst, fmt);
+ fmt2 = talloc_typed_strdup(ctx, fmt);
ub_resolve_async(inst->ub, fmt2, 28, 1, ubres, link_ubres, &async_id);
talloc_free(fmt2);
return -1;
}
-static ssize_t xlat_ptr(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
+static ssize_t xlat_ptr(TALLOC_CTX *ctx, char **out, size_t outlen,
void const *mod_inst, UNUSED void const *xlat_inst,
REQUEST *request, char const *fmt)
{
/* Used and thus impossible value from heap to designate incomplete */
memcpy(ubres, &mod_inst, sizeof(*ubres));
- fmt2 = talloc_typed_strdup(inst, fmt);
+ fmt2 = talloc_typed_strdup(ctx, fmt);
ub_resolve_async(inst->ub, fmt2, 12, 1, ubres, link_ubres, &async_id);
talloc_free(fmt2);