]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Check for from==NULL. Fixes #1054
authorAlan T. DeKok <aland@freeradius.org>
Sun, 14 Jun 2015 14:12:30 +0000 (10:12 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 14 Jun 2015 14:12:51 +0000 (10:12 -0400)
src/main/pair.c
src/modules/rlm_sqlcounter/rlm_sqlcounter.c

index ada2e887f987aef3ebd13158cb7ee93aa9d2668c..e779d2bece8047bd8ed4e8a8c5f63313333b9ed3 100644 (file)
@@ -349,7 +349,7 @@ int paircompare_register_byname(char const *name, DICT_ATTR const *from,
                        fr_strerror_printf("Attribute '%s' already exists.", name);
                        return -1;
                }
-       } else {
+       } else if (from) {
                if (dict_addattr(name, -1, 0, from->type, flags) < 0) {
                        fr_strerror_printf("Failed creating attribute '%s'", name);
                        return -1;
index bfaba344f64cd565c5ffee9b6128b9afe312a181..cad919d6b0e917440eabac8965cd4c3da827123a 100644 (file)
@@ -389,27 +389,37 @@ static int mod_bootstrap(CONF_SECTION *conf, void *instance)
        DICT_ATTR const *da;
        ATTR_FLAGS flags;
 
+       memset(&flags, 0, sizeof(flags));
+       flags.compare = 1;      /* ugly hack */
+       da = dict_attrbyname(inst->counter_name);
+       if (da && (da->type != PW_TYPE_INTEGER64)) {
+               cf_log_err_cs(conf, "Counter attribute %s MUST be integer64", inst->counter_name);
+               return -1;
+       }
+
+       if (!da && (dict_addattr(inst->counter_name, -1, 0, PW_TYPE_INTEGER64, flags) < 0)) {
+               cf_log_err_cs(conf, "Failed to create counter attribute %s: %s", inst->counter_name, fr_strerror());
+               return -1;
+       }
+
        /*
         *  Register the counter comparison operation.
         */
        if (paircompare_register_byname(inst->counter_name, NULL, true, sqlcounter_cmp, inst) < 0) {
-               cf_log_err_cs(conf, "Failed to create counter attribute %s: %s", inst->counter_name, fr_strerror());
+               cf_log_err_cs(conf, "Failed registering counter attribute %s: %s", inst->counter_name, fr_strerror());
                return -1;
        }
 
-
        inst->dict_attr = dict_attrbyname(inst->counter_name);
-       da = dict_attrbyname(inst->counter_name);
-       if (!da) {
+       if (!inst->dict_attr) {
                cf_log_err_cs(conf, "Failed to find counter attribute %s", inst->counter_name);
                return -1;
        }
-       inst->dict_attr = da;
 
        /*
         *  Create a new attribute for the check item.
         */
-       memset(&flags, 0, sizeof(flags));
+       flags.compare = 0;
        if ((dict_addattr(inst->limit_name, -1, 0, PW_TYPE_INTEGER64, flags) < 0) ||
            !(da = dict_attrbyname(inst->limit_name))) {
                cf_log_err_cs(conf, "Failed to create check attribute %s: %s", inst->limit_name, fr_strerror());