From: Arran Cudbard-Bell Date: Fri, 26 Jan 2018 02:47:37 +0000 (-0700) Subject: Deal with empty xlat expansions in a sane way X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb8df294690affcc16e8f5a5e75102d18df927fd;p=thirdparty%2Ffreeradius-server.git Deal with empty xlat expansions in a sane way --- diff --git a/src/main/map.c b/src/main/map.c index e56a5e9bb18..95e98b083cd 100644 --- a/src/main/map.c +++ b/src/main/map.c @@ -1080,21 +1080,34 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, rad_assert(map->lhs->type == TMPL_TYPE_ATTR); rad_assert(map->lhs->tmpl_da); /* We need to know which attribute to create */ - n = map_list_mod_afrom_map(ctx, map_in, map); - if (!n) goto error; - /* - * Fixup zero length result to be an empty string + * Empty value */ if (!rhs_result || !*rhs_result) { - n_vb = fr_value_box_alloc(n->mod->rhs, FR_TYPE_STRING, NULL, false); - if (!n_vb) goto error; + switch (map->lhs->tmpl_da->type) { + case FR_TYPE_STRING: + n = map_list_mod_afrom_map(ctx, map_in, map); + if (!n) goto error; - if (fr_value_box_strdup(n_vb, n_vb, NULL, "", false) < 0) goto error; - fr_cursor_append(&values, n_vb); + n_vb = fr_value_box_alloc(n->mod->rhs, FR_TYPE_STRING, NULL, false); + if (!n_vb) goto error; + + if (fr_value_box_strdup(n_vb, n_vb, NULL, "", false) < 0) goto error; + fr_cursor_append(&values, n_vb); + break; + + default: + goto finish; /* Hmm we could error out? */ + } break; } + /* + * Non-Empty value + */ + n = map_list_mod_afrom_map(ctx, map_in, map); + if (!n) goto error; + (void)fr_cursor_init(&from, rhs_result); while ((vb = fr_cursor_remove(&from))) { if (vb->type != map->lhs->tmpl_da->type) { @@ -1303,7 +1316,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, talloc_free(head); finish: - *out = n; + if (n) *out = n; /* * Reparent ephemeral LHS to the vp_list_mod_t. @@ -1331,6 +1344,7 @@ static inline VALUE_PAIR *map_list_mod_to_vp(TALLOC_CTX *ctx, vp_tmpl_t const *a talloc_free(vp); return NULL; } + VP_VERIFY(vp); /* Check we created something sane */ return vp; } diff --git a/src/tests/keywords/null-value-assign b/src/tests/keywords/null-value-assign new file mode 100644 index 00000000000..e30a2920ef8 --- /dev/null +++ b/src/tests/keywords/null-value-assign @@ -0,0 +1,34 @@ +# +# Reply message doesn't exist, so Tmp-Integer-0 shouldn't be created +# +update request { + Tmp-Integer-0 := "%{Reply-Message}" +} +if (&Tmp-Integer-0) { + fail +} + +# +# NULL valued strings get converted to empty length strings +# +update request { + Tmp-String-0 := "%{Reply-Message}" +} +if (!&Tmp-String-0) { + fail +} +if (&Tmp-String-0 != '') { + fail +} + +# +# NULL valued octet strings get nothing +# +update request { + Tmp-Octets-0 := "%{Reply-Message}" +} +if (&Tmp-Octets-0) { + fail +} + +success