Skip to content

Commit

Permalink
Which to strlen until it passes...
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Mar 19, 2019
1 parent 11ce507 commit 651470a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib/server/xlat_eval.c
Expand Up @@ -205,7 +205,7 @@ static inline void xlat_debug_log_expansion(REQUEST *request, xlat_exp_t const *
if (!RDEBUG_ENABLED2) return;

str = xlat_fmt_aprint(NULL, node);
RDEBUG2("EXPAND %pV", fr_box_strvalue_buffer(str));
RDEBUG2("EXPAND %pV", fr_box_strvalue(str));

/*
* Because it's difficult to keep track of what
Expand All @@ -214,7 +214,7 @@ static inline void xlat_debug_log_expansion(REQUEST *request, xlat_exp_t const *
* well as the original fmt string.
*/
if ((node->type == XLAT_FUNC) && !xlat_is_literal(node->child)) {
RDEBUG2(" (%%{%pV:%pM})", fr_box_strvalue_buffer(node->xlat->name), args);
RDEBUG2(" (%%{%pV:%pM})", fr_box_strvalue(node->xlat->name), args);
}
talloc_free(str);
}
Expand Down
50 changes: 47 additions & 3 deletions src/lib/server/xlat_func.c
Expand Up @@ -2516,9 +2516,9 @@ static xlat_action_t xlat_func_bin(TALLOC_CTX *ctx, fr_cursor_t *out,
* @verbatim %{sub:/<regex>/[flags] <replace> <subject>} @endverbatim
*
*/
static xlat_action_t xlat_func_sub(TALLOC_CTX *ctx, fr_cursor_t *out,
REQUEST *request, UNUSED void const *xlat_inst, UNUSED void *xlat_thread_inst,
fr_value_box_t **in)
static xlat_action_t xlat_func_sub_regex(TALLOC_CTX *ctx, fr_cursor_t *out,
REQUEST *request, UNUSED void const *xlat_inst, UNUSED void *xlat_thread_inst,
fr_value_box_t **in)
{
char const *p, *q, *end;
char const *regex, *rep, *subject;
Expand Down Expand Up @@ -2639,8 +2639,52 @@ static xlat_action_t xlat_func_sub(TALLOC_CTX *ctx, fr_cursor_t *out,

return XLAT_ACTION_DONE;
}
#endif

static xlat_action_t xlat_func_sub(TALLOC_CTX *ctx, fr_cursor_t *out,
REQUEST *request, void const *xlat_inst, void *xlat_thread_inst,
fr_value_box_t **in)
{
char const *p, *q, *end;
char const *pattern, *rep, *subject;
char *buff;
size_t pattern_len, rep_len, subject_len;
/*
* If there's no input, there's no output
*/
if (!*in) {
REDEBUG("No input arguments");
return XLAT_ACTION_FAIL;
}

/*
* Concatenate all input
*/
if (fr_value_box_list_concat(ctx, *in, in, FR_TYPE_STRING, true) < 0) {
RPEDEBUG("Failed concatenating input");
return XLAT_ACTION_FAIL;
}

p = (*in)->vb_strvalue;
end = p + (*in)->vb_length;

if (p == end) {
REDEBUG("Substitution arguments must not be empty");
return XLAT_ACTION_FAIL;
}

if (*p == '/') {
#ifdef HAVE_REGEX_PCRE2
return xlat_func_sub_regex(ctx, out, request, xlat_inst, xlat_thread_inst, in);
#else
REDEBUG("regex based substitutions require libpcre2. "
"Check ${features.regex-pcre2} to determine support");
return XLAT_ACTION_FAIL;
#endif
}


}

static ssize_t xlat_load_balance(TALLOC_CTX *ctx, char **out, NDEBUG_UNUSED size_t outlen,
void const *mod_inst, UNUSED void const *xlat_inst,
Expand Down

0 comments on commit 651470a

Please sign in to comment.