Skip to content

Commit

Permalink
Do compile time checks of literal map values
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Nov 28, 2013
1 parent 02e1d95 commit c0d59f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/lib/valuepair.c
Expand Up @@ -1314,8 +1314,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value)
* attribute.
*/
if ((dval = dict_valbyname(vp->da->attr, vp->da->vendor, value)) == NULL) {
fr_strerror_printf("Unknown value %s for attribute %s",
value, vp->da->name);
fr_strerror_printf("Unknown value '%s' for attribute '%s'", value, vp->da->name);
return false;
}
vp->vp_integer = dval->value;
Expand Down
21 changes: 20 additions & 1 deletion src/main/map.c
Expand Up @@ -340,7 +340,6 @@ value_pair_map_t *radius_cp2map(TALLOC_CTX *ctx, CONF_PAIR *cp,
if (type == T_BARE_WORD) {
if (*value == '&') {
map->src = radius_attr2tmpl(map, value + 1, src_request_def, src_list_def);

} else {
if (!isdigit((int) *value) &&
((strchr(value, ':') != NULL) ||
Expand Down Expand Up @@ -438,6 +437,26 @@ value_pair_map_t *radius_cp2map(TALLOC_CTX *ctx, CONF_PAIR *cp,
}
break;

case VPT_TYPE_LITERAL:
/*
* If LHS is an attribute, and RHS is a literal, we can
* check that the format is correct.
*/
if (map->dst->type == VPT_TYPE_ATTR) {
VALUE_PAIR *vp;
bool ret;

MEM(vp = pairalloc(NULL, map->dst->da));
vp->op = map->op;

ret = pairparsevalue(vp, map->src->name);
talloc_free(vp);
if (!ret) {
cf_log_err(ci, "%s", fr_strerror());
return NULL;
}
}

default:
break;
}
Expand Down

0 comments on commit c0d59f3

Please sign in to comment.