Skip to content

Commit b9c06a8

Browse files
committed
add and use FR_VALUE_BOX_SAFE_FOR_ANY
which lets us *not* escape data which is taken from the configuration files This branch should be deleted when the work is merged to the master branch
1 parent 5a81739 commit b9c06a8

File tree

10 files changed

+42
-9
lines changed

10 files changed

+42
-9
lines changed

src/lib/server/cf_file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,8 @@ static CONF_ITEM *process_if(cf_stack_t *stack)
15431543
.list_def = request_attr_request,
15441544
.allow_unresolved = true,
15451545
.allow_unknown = true
1546-
}
1546+
},
1547+
.literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
15471548
};
15481549

15491550
/*

src/lib/server/cf_parse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM
225225
.allow_unknown = true,
226226
.allow_unresolved = true,
227227
.allow_foreign = true,
228-
}
228+
},
229+
.literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
229230
};
230231
fr_sbuff_t sbuff = FR_SBUFF_IN(cp->value, strlen(cp->value));
231232

src/lib/server/users_file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ static int pairlist_read_internal(TALLOC_CTX *ctx, fr_dict_t const *dict, char c
273273
.prefix = TMPL_ATTR_REF_PREFIX_AUTO,
274274
.list_def = request_attr_request,
275275
.list_presence = TMPL_ATTR_LIST_ALLOW,
276-
}
276+
},
277+
.literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
278+
277279
};
278280
rhs_rules = (tmpl_rules_t) {
279281
.attr = {
@@ -282,7 +284,8 @@ static int pairlist_read_internal(TALLOC_CTX *ctx, fr_dict_t const *dict, char c
282284
.list_def = request_attr_request,
283285
.list_presence = TMPL_ATTR_LIST_ALLOW,
284286
.bare_word_enum = v3_compat,
285-
}
287+
},
288+
.literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
286289
};
287290

288291
while (true) {

src/lib/server/virtual_servers.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,8 @@ int virtual_servers_instantiate(void)
16191619
.dict_def = dict,
16201620
.list_def = request_attr_request,
16211621
},
1622+
1623+
.literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
16221624
};
16231625

16241626
fr_assert(parse_rules.attr.dict_def != NULL);

src/lib/unlang/xlat_builtin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ static xlat_action_t xlat_func_taint(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out,
758758

759759
while ((child = fr_value_box_list_pop_head(&vb->vb_group)) != NULL) {
760760
child->tainted = true;
761+
fr_value_box_mark_unsafe(child);
761762

762763
fr_dcursor_append(out, child);
763764
}

src/lib/util/value.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6358,7 +6358,16 @@ void fr_value_box_list_verify(char const *file, int line, fr_value_box_list_t co
63586358
*/
63596359
void _fr_value_box_mark_safe_for(fr_value_box_t *vb, fr_value_box_safe_for_t safe_for)
63606360
{
6361+
/*
6362+
* Don't over-ride value-boxes which are already safe.
6363+
*/
6364+
if (vb->safe_for == FR_VALUE_BOX_SAFE_FOR_ANY) {
6365+
fr_assert(!vb->tainted);
6366+
return;
6367+
}
6368+
63616369
vb->safe_for = safe_for;
6370+
vb->tainted = false;
63626371
}
63636372

63646373
/** Mark a value-box as "unsafe"
@@ -6379,7 +6388,18 @@ void fr_value_box_mark_unsafe(fr_value_box_t *vb)
63796388
*/
63806389
void fr_value_box_list_mark_safe_for(fr_value_box_list_t *list, fr_value_box_safe_for_t safe_for)
63816390
{
6382-
fr_value_box_list_foreach(list, vb) vb->safe_for = safe_for;
6391+
fr_value_box_list_foreach(list, vb) {
6392+
/*
6393+
* Don't over-ride value-boxes which are already safe.
6394+
*/
6395+
if (vb->safe_for == FR_VALUE_BOX_SAFE_FOR_ANY) {
6396+
fr_assert(!vb->tainted);
6397+
6398+
} else {
6399+
vb->safe_for = safe_for;
6400+
vb->tainted = false;
6401+
}
6402+
}
63836403
}
63846404

63856405
/** Check truthiness of values.

src/lib/util/value.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ typedef union {
154154
*/
155155
typedef uintptr_t fr_value_box_safe_for_t;
156156

157+
#define FR_VALUE_BOX_SAFE_FOR_NONE ((uintptr_t) 0)
158+
#define FR_VALUE_BOX_SAFE_FOR_ANY (~((uintptr_t) 0))
159+
157160
/** Union containing all data types supported by the server
158161
*
159162
* This union contains all data types that can be represented by fr_pair_ts. It may also be used in other parts
@@ -1052,7 +1055,7 @@ void _fr_value_box_mark_safe_for(fr_value_box_t *box, fr_value_box_safe_for_t s
10521055
void fr_value_box_mark_unsafe(fr_value_box_t *box)
10531056
CC_HINT(nonnull);
10541057

1055-
#define fr_value_box_is_safe_for(_box, _safe_for) (_box->safe_for == (fr_value_box_safe_for_t)_safe_for)
1058+
#define fr_value_box_is_safe_for(_box, _safe_for) ((_box->safe_for == (fr_value_box_safe_for_t)_safe_for) || (_box->safe_for == FR_VALUE_BOX_SAFE_FOR_ANY))
10561059

10571060
void fr_value_box_list_mark_safe_for(fr_value_box_list_t *list, fr_value_box_safe_for_t safe_for);
10581061

src/modules/rlm_linelog/rlm_linelog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ static unlang_action_t CC_HINT(nonnull) mod_do_linelog(rlm_rcode_t *p_result, mo
767767
.xlat = {
768768
.runtime_el = unlang_interpret_event_list(request),
769769
},
770-
.at_runtime = true
770+
.at_runtime = true,
771+
.literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
771772
});
772773
if (!vpt) {
773774
REMARKER(tmpl_str, -slen, "%s", fr_strerror());

src/modules/rlm_radius/rlm_radius.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ static int status_check_update_parse(TALLOC_CTX *ctx, void *out, void *parent,
498498
.list_def = request_attr_request,
499499
.list_presence = TMPL_ATTR_LIST_FORBID,
500500
.prefix = TMPL_ATTR_REF_PREFIX_AUTO,
501-
}
501+
},
502+
.literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
502503
};
503504

504505
rcode = map_afrom_cs(ctx, head, cs, &parse_rules, &parse_rules, status_check_verify, parent, 128);

src/tests/keywords/regex-escape

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ string test_string2
88
# Strings which are expanded in a regex have regex special
99
# characters escaped. Because the input strings are unsafe.
1010
#
11-
test_string1 := "example.com"
11+
test_string1 := %taint("example.com")
1212
test_string2 := "exampleXcom"
1313

1414
if ("exampleXcom" =~ /%{test_string1}/) {

0 commit comments

Comments
 (0)