From: Alan T. DeKok Date: Wed, 11 Mar 2026 21:32:28 +0000 (-0400) Subject: move function needing sbuff out of talloc.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf580891722cf3c9d9890878547e080244fa5803;p=thirdparty%2Ffreeradius-server.git move function needing sbuff out of talloc.c because otherwise we have circular includes of talloc to sbuff to talloc, and things don't always work as well as they should. --- diff --git a/src/lib/kafka/base.c b/src/lib/kafka/base.c index bd3aaf98934..d6db2f58c70 100644 --- a/src/lib/kafka/base.c +++ b/src/lib/kafka/base.c @@ -462,7 +462,7 @@ static int kafka_config_parse(TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *ba cf_item_mark_parsed(cp_p); } - slen = talloc_array_concat(agg, array, kctx->string_sep); + slen = fr_sbuff_array_concat(agg, array, kctx->string_sep); talloc_free(array); if (slen < 0) return -1; diff --git a/src/lib/util/file.h b/src/lib/util/file.h index 80f8bfbbb5c..d4f1a50faed 100644 --- a/src/lib/util/file.h +++ b/src/lib/util/file.h @@ -28,7 +28,7 @@ RCSIDH(util_file_h, "$Id$") extern "C" { #endif -#include +#include #include #ifdef HAVE_DIRENT_H diff --git a/src/lib/util/md4.c b/src/lib/util/md4.c index 7fbfd519634..27070e990c5 100644 --- a/src/lib/util/md4.c +++ b/src/lib/util/md4.c @@ -222,6 +222,8 @@ static fr_md4_funcs_t md4_openssl_funcs = { /* This is the central step in the MD4 algorithm. */ #define MD4STEP(f, w, x, y, z, data, s) (w += f(x, y, z) + data, w = w << s | w >> (32 - s)) +DIAG_OFF(cast-align) + /** The core of the MD4 algorithm * * This alters an existing MD4 hash to reflect the addition of 16 diff --git a/src/lib/util/perm.c b/src/lib/util/perm.c index 23acf9056cb..6b25d317c9a 100644 --- a/src/lib/util/perm.c +++ b/src/lib/util/perm.c @@ -187,6 +187,8 @@ check: return 0; } +DIAG_OFF(cast-align) + /** Resolve a uid to a passwd entry * * Resolves a uid to a passwd entry. The memory to hold the diff --git a/src/lib/util/sbuff.c b/src/lib/util/sbuff.c index d37baed7587..35ef37812c3 100644 --- a/src/lib/util/sbuff.c +++ b/src/lib/util/sbuff.c @@ -2317,3 +2317,38 @@ void fr_sbuff_parse_rules_debug(FILE *fp, fr_sbuff_parse_rules_t const *p_rules) fprintf(fp, "\n"); } } + +/** Concat an array of strings (not NULL terminated), with a string separator + * + * @param[out] out Where to write the resulting string. + * @param[in] array of strings to concat. + * @param[in] sep to insert between elements. May be NULL. + * @return + * - >= 0 on success - length of the string created. + * - <0 on failure. How many bytes we would need. + */ +fr_slen_t fr_sbuff_array_concat(fr_sbuff_t *out, char const * const *array, char const *sep) +{ + fr_sbuff_t our_out = FR_SBUFF(out); + size_t len = talloc_array_length(array); + char const * const * p; + char const * const * end; + fr_sbuff_escape_rules_t e_rules = { + .name = __FUNCTION__, + .chr = '\\' + }; + + if (sep) e_rules.subs[(uint8_t)*sep] = *sep; + + for (p = array, end = array + len; + (p < end); + p++) { + if (*p) FR_SBUFF_RETURN(fr_sbuff_in_escape, &our_out, *p, strlen(*p), &e_rules); + + if (sep && ((p + 1) < end)) { + FR_SBUFF_RETURN(fr_sbuff_in_strcpy, &our_out, sep); + } + } + + FR_SBUFF_SET_RETURN(out, &our_out); +} diff --git a/src/lib/util/sbuff.h b/src/lib/util/sbuff.h index 3cba33ebfb3..83c357265ae 100644 --- a/src/lib/util/sbuff.h +++ b/src/lib/util/sbuff.h @@ -1860,6 +1860,9 @@ void fr_sbuff_parse_rules_debug(FILE *fp, fr_sbuff_parse_rules_t const *p_rules */ #define fr_sbuff_as_percent_s(_sbuff) (int) fr_sbuff_remaining(_sbuff), fr_sbuff_current(_sbuff) +fr_slen_t fr_sbuff_array_concat(fr_sbuff_t *out, char const * const *array, char const *sep) CC_HINT(nonnull(1,2)); + + #ifdef __cplusplus } #endif diff --git a/src/lib/util/talloc.c b/src/lib/util/talloc.c index 97a69e1daa8..bc2a12488c2 100644 --- a/src/lib/util/talloc.c +++ b/src/lib/util/talloc.c @@ -956,41 +956,6 @@ void **talloc_array_null_strip(void **array) return new; } -/** Concat an array of strings (not NULL terminated), with a string separator - * - * @param[out] out Where to write the resulting string. - * @param[in] array of strings to concat. - * @param[in] sep to insert between elements. May be NULL. - * @return - * - >= 0 on success - length of the string created. - * - <0 on failure. How many bytes we would need. - */ -fr_slen_t talloc_array_concat(fr_sbuff_t *out, char const * const *array, char const *sep) -{ - fr_sbuff_t our_out = FR_SBUFF(out); - size_t len = talloc_array_length(array); - char const * const * p; - char const * const * end; - fr_sbuff_escape_rules_t e_rules = { - .name = __FUNCTION__, - .chr = '\\' - }; - - if (sep) e_rules.subs[(uint8_t)*sep] = *sep; - - for (p = array, end = array + len; - (p < end); - p++) { - if (*p) FR_SBUFF_RETURN(fr_sbuff_in_escape, &our_out, *p, strlen(*p), &e_rules); - - if (sep && ((p + 1) < end)) { - FR_SBUFF_RETURN(fr_sbuff_in_strcpy, &our_out, sep); - } - } - - FR_SBUFF_SET_RETURN(out, &our_out); -} - /** Callback to free the autofree ctx on global exit * */ diff --git a/src/lib/util/talloc.h b/src/lib/util/talloc.h index d0262709a8b..7bf1956337e 100644 --- a/src/lib/util/talloc.h +++ b/src/lib/util/talloc.h @@ -43,7 +43,6 @@ DIAG_ON(documentation) #include /* Very easy to miss including in special builds */ #include #include -#include #undef talloc_autofree_context /** The original function is deprecated, so replace it with our version @@ -249,9 +248,6 @@ void **talloc_array_null_terminate(void **array); void **talloc_array_null_strip(void **array); -fr_slen_t talloc_array_concat(fr_sbuff_t *out, char const * const *array, char const *sep); - - /** Free const'd memory * * @param[in] ptr to free.