From: Alan T. DeKok Date: Wed, 19 Jan 2022 16:11:00 +0000 (-0500) Subject: remove string/octets prepend. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad40bda5a855cc5ad0394906314c6465c78988ce;p=thirdparty%2Ffreeradius-server.git remove string/octets prepend. It's not really needed, and it interferes with the ability to add XOR --- diff --git a/doc/antora/modules/reference/pages/unlang/edit.adoc b/doc/antora/modules/reference/pages/unlang/edit.adoc index 00118321948..0836877937b 100644 --- a/doc/antora/modules/reference/pages/unlang/edit.adoc +++ b/doc/antora/modules/reference/pages/unlang/edit.adoc @@ -297,7 +297,7 @@ The operators also apply to non-integer attributes. | := | Override the attribute with the contents with the __. If the attribute already exists, its value is over-written. If the attribute does not exist, it is created, and the contents set to thex value of the __ | += | Perform string append. The contents of the __ are appended to the __. | -= | Inverse of string append. The contents of the __ are deleted from from the __, if the `__` is a suffix of __ -| ^= | Perform string prepend. The contents of the __ are prepended to the __. +| ^= | Perform logical "xor". The contents of the __ are "xor"ed with the contents of the __. Both strings must be of the same length. | \|= | Perform logical "or". The value of the __ is "or"ed with the contents of the __. Both strings must be of the same length. | \&= | Perform logical "and". The value of the __ is "and"ed with the contents of the __. Both strings must be of the same length. | \<<= | Perform left shift / truncation. The first __ bytes of __ are dropped. i.e. shifted off of the start of the string. diff --git a/src/lib/util/calc.c b/src/lib/util/calc.c index 0921c2c3640..f6f023cad3a 100644 --- a/src/lib/util/calc.c +++ b/src/lib/util/calc.c @@ -456,7 +456,7 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons len = a->length + b->length; switch (op) { - case T_OP_PREPEND: /* dst = b . a */ + case T_ADD: /* dst = a . b */ buf = talloc_array(ctx, uint8_t, len); if (!buf) { oom: @@ -464,16 +464,6 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons return -1; } - memcpy(buf, b->vb_octets, b->vb_length); - memcpy(buf + b->vb_length, a->vb_octets, a->vb_length); - - fr_value_box_memdup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted); - break; - - case T_ADD: /* dst = a . b */ - 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); @@ -593,7 +583,7 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons len = a->length + b->length; switch (op) { - case T_OP_PREPEND: /* dst = b . a */ + case T_ADD: buf = talloc_array(ctx, char, len + 1); if (!buf) { oom: @@ -601,18 +591,6 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons return -1; } - len = a->vb_length + b->vb_length; - memcpy(buf, b->vb_strvalue, b->vb_length); - memcpy(buf + b->vb_length, a->vb_strvalue, a->vb_length); - buf[len] = '\0'; - - fr_value_box_bstrndup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted); - break; - - case T_ADD: - buf = talloc_array(ctx, char, len + 1); - if (!buf) goto oom; - len = a->vb_length + b->vb_length; memcpy(buf, a->vb_strvalue, a->vb_length); memcpy(buf + a->vb_length, b->vb_strvalue, b->vb_length); @@ -1278,23 +1256,6 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint */ if (hint == FR_TYPE_NULL) do { switch (op) { - case T_OP_PREPEND: - /* - * Pick the existing type if we have a - * variable-sized type. Otherwise, pick - * octets. - */ - if (fr_type_is_variable_size(a->type)) { - hint = a->type; - - } else if (fr_type_is_variable_size(b->type)) { - hint = b->type; - - } else { - hint = FR_TYPE_OCTETS; - } - break; - case T_OP_CMP_EQ: case T_OP_NE: case T_OP_GE: @@ -1418,7 +1379,6 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint case T_DIV: case T_AND: case T_OR: - case T_OP_PREPEND: case T_RSHIFT: case T_LSHIFT: fr_assert(hint != FR_TYPE_NULL); @@ -1503,10 +1463,6 @@ int fr_value_calc_assignment_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_token_t rcode = fr_value_calc_binary_op(ctx, &out, dst->type, dst, T_SUB, src); break; - case T_OP_PREPEND: - rcode = fr_value_calc_binary_op(ctx, dst, dst->type, dst, op, src); - break; - case T_OP_AND_EQ: rcode = fr_value_calc_binary_op(ctx, &out, dst->type, dst, T_OR, src); break; diff --git a/src/tests/unit/calc.txt b/src/tests/unit/calc.txt index a85ea644e4e..04505c285cb 100644 --- a/src/tests/unit/calc.txt +++ b/src/tests/unit/calc.txt @@ -63,10 +63,6 @@ match a # # octets # -# octets prepend -calc octets "a" ^ octets "b" -> octets -match 0x6261 - # octets append calc octets "a" . octets "b" -> octets match 0x6162 @@ -81,6 +77,10 @@ match 0x60 calc octets "a" | octets "b" -> octets match 0x63 +# octets xor +#calc octets "a" ^ octets "b" -> octets +#match 0x03 + # we can "fake out" structs by just appending stuff calc ipaddr 127.0.0.1 . ipaddr 127.0.0.2 -> octets match 0x7f0000017f000002 @@ -155,4 +155,4 @@ calc string "2" += string "test" match 2test count -match 64 +match 62