From: Arran Cudbard-Bell Date: Sun, 15 May 2016 16:03:02 +0000 (-0400) Subject: Add base type macro to ensure we don't get tripped up by flags X-Git-Tag: branch_3_1_x~373 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4073841b0ea192e0e40290b03009e7c362ecb475;p=thirdparty%2Ffreeradius-server.git Add base type macro to ensure we don't get tripped up by flags --- diff --git a/src/include/conffile.h b/src/include/conffile.h index 31e1f39937d..7b5c93f7317 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -240,6 +240,8 @@ typedef struct timeval _timeval_t; #define PW_TYPE_IS_SET (1 << 21) //!< Write whether this config item was //!< left as the default to is_set_offset //!< or is_set_ptr. + +#define PW_BASE_TYPE(_t) (0xff & (_t)) /* @} **/ #define FR_INTEGER_COND_CHECK(_name, _var, _cond, _new)\ diff --git a/src/main/command.c b/src/main/command.c index 825e4cf693d..58081cd255b 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -2316,7 +2316,7 @@ static int command_set_module_config(rad_listen_t *listener, int argc, char *arg /* * FIXME: Recurse into sub-types somehow... */ - if (variables[i].type == PW_TYPE_SUBSECTION) continue; + if (PW_BASE_TYPE(variables[i].type) == PW_TYPE_SUBSECTION) continue; if (strcmp(variables[i].name, argv[1]) == 0) { rcode = i; diff --git a/src/main/conffile.c b/src/main/conffile.c index 0e4cdbdab5f..313e9ee1214 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -1435,7 +1435,7 @@ int cf_section_parse_pass2(CONF_SECTION *cs, void *base, CONF_PARSER const varia attribute = (type & PW_TYPE_ATTRIBUTE); multi = (type & PW_TYPE_MULTI); - type &= 0xff; /* normal types are small */ + type = PW_BASE_TYPE(type); /* normal types are small */ /* * It's a section, recurse! @@ -1633,7 +1633,7 @@ static int cf_pair_parse_value(void *out, TALLOC_CTX *ctx, CONF_SECTION *cs, CON if (required) cant_be_empty = true; /* May want to review this in the future... */ - type &= 0xff; /* normal types are small */ + type = PW_BASE_TYPE(type); /* normal types are small */ /* * Everything except templates must have a base type. @@ -1917,7 +1917,7 @@ static int cf_pair_default(CONF_PAIR **out, CONF_SECTION *cs, char const *name, CONF_PAIR *cp; char buffer[8192]; - type &= 0xff; + type = PW_BASE_TYPE(type); /* * Defaults may need their values expanding @@ -2098,7 +2098,7 @@ int cf_pair_parse(CONF_SECTION *cs, char const *name, unsigned int type, void *d * We don't NULL terminate. Consumer must use * talloc_array_length(). */ - } else switch (type & 0xff) { + } else switch (PW_BASE_TYPE(type)) { case PW_TYPE_BOOLEAN: array = (void **)talloc_zero_array(cs, bool, count); break; @@ -2205,7 +2205,7 @@ static void cf_section_parse_init(CONF_SECTION *cs, void *base, CONF_PARSER cons int i; for (i = 0; variables[i].name != NULL; i++) { - if ((variables[i].type & 0xff) == PW_TYPE_SUBSECTION) { + if (PW_BASE_TYPE(variables[i].type) == PW_TYPE_SUBSECTION) { CONF_SECTION *subcs; if (!variables[i].dflt) continue; @@ -2233,7 +2233,7 @@ static void cf_section_parse_init(CONF_SECTION *cs, void *base, CONF_PARSER cons continue; } - if ((variables[i].type != PW_TYPE_STRING) && + if ((PW_BASE_TYPE(variables[i].type) != PW_TYPE_STRING) && (variables[i].type != PW_TYPE_FILE_INPUT) && (variables[i].type != PW_TYPE_FILE_OUTPUT)) { continue; @@ -2312,7 +2312,7 @@ int cf_section_parse(CONF_SECTION *cs, void *base, CONF_PARSER const *variables) /* * Handle subsections specially */ - if (variables[i].type == PW_TYPE_SUBSECTION) { + if (PW_BASE_TYPE(variables[i].type) == PW_TYPE_SUBSECTION) { CONF_SECTION *subcs; subcs = cf_section_sub_find(cs, variables[i].name); diff --git a/src/main/unittest.c b/src/main/unittest.c index 6cc3fc16593..71395252b52 100644 --- a/src/main/unittest.c +++ b/src/main/unittest.c @@ -495,7 +495,7 @@ static ssize_t xlat_poke(char **out, size_t outlen, for (i = 0; variables[i].name != NULL; i++) { int ret; - if (variables[i].type == PW_TYPE_SUBSECTION) continue; + if (PW_BASE_TYPE(variables[i].type) == PW_TYPE_SUBSECTION) continue; /* else it's a CONF_PAIR */ /*