From: Arran Cudbard-Bell Date: Sat, 23 Mar 2019 15:41:40 +0000 (+0700) Subject: s/talloc_realloc_bstr/talloc_bstr_realloc/g X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58ca6d67cedb7e390b82e3ee66707bb0cc022f1e;p=thirdparty%2Ffreeradius-server.git s/talloc_realloc_bstr/talloc_bstr_realloc/g --- diff --git a/src/lib/server/cf_util.c b/src/lib/server/cf_util.c index e13dc1053b4..52fac5dbcd1 100644 --- a/src/lib/server/cf_util.c +++ b/src/lib/server/cf_util.c @@ -1752,7 +1752,7 @@ int cf_pair_in_table(int32_t *out, FR_NAME_NUMBER const *table, CONF_PAIR *cp) /* * Trim the final ", " */ - MEM(list = talloc_realloc_bstr(NULL, list, talloc_array_length(list) - 3)); + MEM(list = talloc_bstr_realloc(NULL, list, talloc_array_length(list) - 3)); cf_log_err(cp, "Invalid value \"%s\". Expected one of %s", cf_pair_value(cp), list); diff --git a/src/lib/server/xlat_eval.c b/src/lib/server/xlat_eval.c index 7283cb471f7..44eab60a83b 100644 --- a/src/lib/server/xlat_eval.c +++ b/src/lib/server/xlat_eval.c @@ -798,7 +798,7 @@ xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_cursor_t *out, * Shrink the buffer */ if ((node->xlat->buf_len > 0) && (slen > 0)) { - MEM(str = talloc_realloc_bstr(ctx, str, (size_t)slen)); + MEM(str = talloc_bstr_realloc(ctx, str, (size_t)slen)); } /* diff --git a/src/lib/server/xlat_tokenize.c b/src/lib/server/xlat_tokenize.c index 9447b646641..c95f6846800 100644 --- a/src/lib/server/xlat_tokenize.c +++ b/src/lib/server/xlat_tokenize.c @@ -685,7 +685,7 @@ static ssize_t xlat_tokenize_literal(TALLOC_CTX *ctx, xlat_exp_t **head, char co /* * Shrink the buffer to the right size */ - MEM(start = talloc_realloc_bstr(ctx, start, node->len)); + MEM(start = talloc_bstr_realloc(ctx, start, node->len)); node->fmt = start; return p - fmt; diff --git a/src/lib/util/regex.c b/src/lib/util/regex.c index 4292b1d6506..55d2325e574 100644 --- a/src/lib/util/regex.c +++ b/src/lib/util/regex.c @@ -503,7 +503,7 @@ again: * ...and as pcre2_substitute just succeeded actual_len does not include \0. */ if (actual_len < (buff_len - 1)) { - buff = talloc_realloc_bstr(ctx, buff, actual_len); + buff = talloc_bstr_realloc(ctx, buff, actual_len); if (!buff) { fr_strerror_printf("reallocing pcre2_substitute result buffer failed"); return -1; diff --git a/src/lib/util/talloc.c b/src/lib/util/talloc.c index 0f650c5435d..431bd545b84 100644 --- a/src/lib/util/talloc.c +++ b/src/lib/util/talloc.c @@ -352,16 +352,23 @@ char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t fro * * @param[in] ctx to realloc buffer into. * @param[in] in string to trim. Will be invalid after - * this function returns. + * this function returns. If NULL a new zero terminated + * buffer of inlen bytes will be allocated. * @param[in] inlen Length to trim string to. * @return * - The realloced string on success. in then points to invalid memory. * - NULL on failure. In will still be valid. */ -char *talloc_realloc_bstr(TALLOC_CTX *ctx, char *in, size_t inlen) +char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen) { char *n; + if (!in) { + n = talloc_array(ctx, char, inlen); + n[0] = '\0'; + return n; + } + n = talloc_realloc_size(ctx, in, inlen + 1); if (!n) return NULL; diff --git a/src/lib/util/talloc.h b/src/lib/util/talloc.h index 1cf9f3b4571..e616934fa8b 100644 --- a/src/lib/util/talloc.h +++ b/src/lib/util/talloc.h @@ -52,7 +52,7 @@ char *talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen); char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t from_len); -char *talloc_realloc_bstr(TALLOC_CTX *ctx, char *in, size_t inlen); +char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen); char *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from); diff --git a/src/modules/rlm_cipher/rlm_cipher.c b/src/modules/rlm_cipher/rlm_cipher.c index 90ae9935d7c..0629b7fa24b 100644 --- a/src/modules/rlm_cipher/rlm_cipher.c +++ b/src/modules/rlm_cipher/rlm_cipher.c @@ -674,7 +674,7 @@ static xlat_action_t cipher_rsa_decrypt_xlat(TALLOC_CTX *ctx, fr_cursor_t *out, { char *n; - n = talloc_realloc_bstr(ctx, plaintext, plaintext_len); + n = talloc_bstr_realloc(ctx, plaintext, plaintext_len); if (unlikely(!n)) { REDEBUG("Failed shrinking plaintext buffer"); talloc_free(plaintext);