From: Arran Cudbard-Bell Date: Sun, 5 Dec 2021 15:13:42 +0000 (-0500) Subject: Revert "Use the allocation functions to allocate buffers in cal.c instead of doing... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb164b26b41360b8b0928eeae8147980884fceab;p=thirdparty%2Ffreeradius-server.git Revert "Use the allocation functions to allocate buffers in cal.c instead of doing it manually" This reverts commit 0f677c5ff474e88942bf25b49aafd5b97bcdfea4. --- diff --git a/src/lib/util/calc.c b/src/lib/util/calc.c index 2dcc77a5a67..d02cb861783 100644 --- a/src/lib/util/calc.c +++ b/src/lib/util/calc.c @@ -394,7 +394,8 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons switch (op) { case T_OP_PREPEND: /* dst = b . a */ - if (unlikely(fr_value_box_mem_alloc(ctx, &buf, dst, dst->enumv, len, a->tainted | b->tainted) < 0)) { + buf = talloc_array(ctx, uint8_t, len); + if (!buf) { oom: fr_strerror_const("Out of memory"); return -1; @@ -402,13 +403,20 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons memcpy(buf, b->vb_octets, b->vb_length); memcpy(buf + b->vb_length, a->vb_octets, a->vb_length); + + fr_value_box_clear_value(dst); + fr_value_box_memdup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted); break; case T_ADD: /* dst = a . b */ - if (unlikely(fr_value_box_mem_alloc(ctx, &buf, dst, dst->enumv, len, a->tainted | b->tainted) < 0)) goto oom; + buf = talloc_array(ctx, uint8_t, len); + if (!buf) goto oom; memcpy(buf, a->vb_octets, a->vb_length); memcpy(buf + a->vb_length, b->vb_octets, b->vb_length); + + fr_value_box_clear_value(dst); + fr_value_box_memdup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted); break; case T_SUB: @@ -426,8 +434,13 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons } len = a->vb_length - b->vb_length; - if (unlikely(fr_value_box_mem_alloc(ctx, &buf, dst, dst->enumv, len, a->tainted | b->tainted) < 0)) goto oom; + buf = talloc_array(ctx, uint8_t, len); + if (!buf) goto oom; + memcpy(buf, a->vb_strvalue, len); + + fr_value_box_clear_value(dst); + fr_value_box_memdup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted); break; case T_AND: @@ -437,17 +450,29 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons return -1; } - if (unlikely(fr_value_box_mem_alloc(ctx, &buf, dst, dst->enumv, a->vb_length, a->tainted | b->tainted) < 0)) goto oom; + buf = talloc_array(ctx, uint8_t, a->vb_length); + if (!buf) goto oom; - for (len = 0; len < a->vb_length; len++) buf[len] = a->vb_octets[len] & b->vb_octets[len]; + for (len = 0; len < a->vb_length; len++) { + buf[len] = a->vb_octets[len] & b->vb_octets[len]; + } + + fr_value_box_clear_value(dst); + fr_value_box_memdup_shallow(dst, dst->enumv, buf, a->vb_length, a->tainted | b->tainted); break; case T_OR: if (a->vb_length != b->vb_length) goto length_error; - if (unlikely(fr_value_box_mem_alloc(ctx, &buf, dst, dst->enumv, a->vb_length, a->tainted | b->tainted) < 0)) goto oom; + buf = talloc_array(ctx, uint8_t, a->vb_length); + if (!buf) goto oom; - for (len = 0; len < a->vb_length; len++) buf[len] = a->vb_octets[len] | b->vb_octets[len]; + for (len = 0; len < a->vb_length; len++) { + buf[len] = a->vb_octets[len] | b->vb_octets[len]; + } + + fr_value_box_clear_value(dst); + fr_value_box_memdup_shallow(dst, dst->enumv, buf, a->vb_length, a->tainted | b->tainted); break; default: @@ -482,7 +507,8 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons switch (op) { case T_OP_PREPEND: /* dst = b . a */ - if (unlikely(fr_value_box_bstr_alloc(ctx, &buf, dst, dst->enumv, len, a->tainted | b->tainted) < 0)) { + buf = talloc_array(ctx, char, len + 1); + if (!buf) { oom: fr_strerror_const("Out of memory"); return -1; @@ -491,13 +517,21 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons memcpy(buf, b->vb_strvalue, b->vb_length); memcpy(buf + b->vb_length, a->vb_strvalue, a->vb_length); buf[a->vb_length + b->vb_length] = '\0'; + + fr_value_box_clear_value(dst); + fr_value_box_strdup_shallow(dst, dst->enumv, buf, a->tainted | b->tainted); break; case T_ADD: - if (unlikely(fr_value_box_bstr_alloc(ctx, &buf, dst, dst->enumv, len, a->tainted | b->tainted) < 0)) goto oom; + buf = talloc_array(ctx, char, len + 1); + if (!buf) goto oom; memcpy(buf, a->vb_strvalue, a->vb_length); memcpy(buf + a->vb_length, b->vb_strvalue, b->vb_length); + buf[a->vb_length + b->vb_length] = '\0'; + + fr_value_box_clear_value(dst); + fr_value_box_strdup_shallow(dst, dst->enumv, buf, a->tainted | b->tainted); break; case T_SUB: @@ -515,9 +549,14 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons } len = a->vb_length - b->vb_length; + buf = talloc_array(ctx, char, len + 1); + if (!buf) goto oom; - if (unlikely(fr_value_box_bstr_alloc(ctx, &buf, dst, dst->enumv, len, a->tainted | b->tainted) < 0)) goto oom; memcpy(buf, a->vb_strvalue, len); + buf[len] = '\0'; + + fr_value_box_clear_value(dst); + fr_value_box_strdup_shallow(dst, dst->enumv, buf, a->tainted | b->tainted); break; default: