]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add value_box to xlat node, and make XLAT_LITERAL use it
authorAlan T. DeKok <aland@freeradius.org>
Tue, 23 Nov 2021 15:19:12 +0000 (10:19 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 23 Nov 2021 15:26:24 +0000 (10:26 -0500)
right now we don't pass (or therefore use) any tainting flag.
That should arguably be fixed.

src/lib/unlang/xlat_eval.c
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_tokenize.c

index be04f023fc8de7ebb62976697295026dfb0d9cce..eaf0e57cf9d044b07291ca5cca512888c7a8bffb 100644 (file)
@@ -1274,7 +1274,7 @@ xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_t con
                         *      because references aren't threadsafe.
                         */
                        MEM(value = fr_value_box_alloc_null(ctx));
-                       fr_value_box_bstrdup_buffer(value, value, NULL, node->fmt, false);
+                       if (fr_value_box_copy(ctx, value, &node->data) < 0) goto fail;
                        fr_dcursor_append(out, value);
                        continue;
 
@@ -1444,7 +1444,12 @@ static char *xlat_sync_eval(TALLOC_CTX *ctx, request_t *request, xlat_exp_t cons
         */
        case XLAT_LITERAL:
                XLAT_DEBUG("%.*sxlat_sync_eval LITERAL", lvl, xlat_spaces);
-               return talloc_typed_strdup(ctx, node->fmt);
+               {
+                       char *out;
+                       slen = fr_value_box_aprint(ctx, &out, &node->data, NULL);
+                       if (slen < 0) return NULL;
+                       return out;
+               }
 
        case XLAT_GROUP:
                XLAT_DEBUG("%.*sxlat_sync_eval CHILD", lvl, xlat_spaces);
index 4c12f40e354ca79720a6c3b5b3f548b6ef210bb1..74dafb41294dc34c6e1a69e6ae7ba634801933f1 100644 (file)
@@ -137,6 +137,11 @@ struct xlat_exp {
                /** An xlat function call
                 */
                xlat_call_t     call;
+
+               /** A value box
+                *
+                */
+               fr_value_box_t  data;
        };
 };
 
index a49e96f74803fa632f0711ce6a7806fcc87aa99f..45edc4116d4e499d81f54226a43b5312e105644c 100644 (file)
@@ -123,6 +123,7 @@ static inline CC_HINT(always_inline) xlat_exp_t *xlat_exp_alloc_null(TALLOC_CTX
        return node;
 }
 
+
 /** Allocate an xlat node
  *
  * @param[in] ctx      to allocate node in.
@@ -140,7 +141,11 @@ static inline CC_HINT(always_inline) xlat_exp_t *xlat_exp_alloc(TALLOC_CTX *ctx,
        node->type = type;
        if (in) node->fmt = talloc_bstrndup(node, in, inlen);
 
-       node->flags.pure = (type == XLAT_LITERAL);
+       if (type == XLAT_LITERAL) {
+               node->flags.pure = true;         /* literals are always pure */
+               node->flags.needs_async = false; /* literals are always non-async */
+               fr_value_box_strdup_shallow(&node->data, NULL, node->fmt, false);
+       }
 
        return node;
 }
@@ -155,8 +160,8 @@ static inline CC_HINT(always_inline) void xlat_exp_set_type(xlat_exp_t *node, xl
        node->type = type;
 
        if (type == XLAT_LITERAL) {
-               node->flags.needs_async = false; /* literals are always non-async */
                node->flags.pure = true;         /* literals are always pure */
+               node->flags.needs_async = false; /* literals are always non-async */
        }
 }
 
@@ -468,6 +473,14 @@ static inline int xlat_validate_function_args(xlat_exp_t *node)
                        return -1;
                }
 
+               /*
+                *      The argument isn't of the correct type.  Cast it.
+                */
+               if ((child->type == XLAT_LITERAL) && (child->data.type != arg_p->type) &&
+                   (fr_value_box_cast_in_place(child, &child->data, arg_p->type, NULL) < 0)) {
+                       return -1;
+               }
+
                child = child->next;
        }
 
@@ -947,9 +960,10 @@ static int xlat_tokenize_literal(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_
                if (len > 0) {
                        xlat_exp_set_type(node, XLAT_LITERAL);
                        xlat_exp_set_name_buffer_shallow(node, str);
+                       fr_value_box_strdup_shallow(&node->data, NULL, str, false);
 
                        XLAT_DEBUG("LITERAL (%s)<-- %pV",
-                                  escapes ? escapes->name : "(none)",
+                                  escapes ? escapes->name : "(none)",XXX
                                   fr_box_strvalue_len(str, talloc_array_length(str) - 1));
                        XLAT_HEXDUMP((uint8_t const *)str, talloc_array_length(str) - 1, " LITERAL ");
                        fr_cursor_insert(&cursor, node);
@@ -1166,7 +1180,7 @@ ssize_t xlat_print(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff_escape_rule
                        goto next;
 
                case XLAT_LITERAL:
-                       FR_SBUFF_IN_ESCAPE_BUFFER_RETURN(out, node->fmt, e_rules);
+                       FR_SBUFF_RETURN(fr_value_box_print, out, &node->data, e_rules);
                        goto next;
 
                case XLAT_ONE_LETTER:
@@ -1417,7 +1431,9 @@ ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *fla
                                                            value_parse_rules_single_quoted.terminals,
                                                            value_parse_rules_single_quoted.escapes);
                        if (slen < 0) goto error;
+
                        xlat_exp_set_name_buffer_shallow(node->child, str);
+                       fr_value_box_strdup_shallow(&node->child->data, NULL, str, false);
                        xlat_flags_merge(flags, &node->flags);
                }
                        break;