From: Alan T. DeKok Date: Tue, 5 Nov 2019 14:25:19 +0000 (-0500) Subject: make more dict functions take const X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f063890eb37823f362c22843d2a9db87ebe907f;p=thirdparty%2Ffreeradius-server.git make more dict functions take const the caller isn't supposed to modify them, but the dict code can. --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index b93cde3e78e..cbb8a7b2d03 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -245,7 +245,7 @@ extern bool const fr_dict_non_data_types[FR_TYPE_MAX + 1]; * * @{ */ -int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, int attr, +int fr_dict_attr_add(fr_dict_t const *dict, fr_dict_attr_t const *parent, char const *name, int attr, fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1,2,3)); int fr_dict_enum_add_alias(fr_dict_attr_t const *da, char const *alias, @@ -394,7 +394,7 @@ int fr_dict_internal_afrom_file(fr_dict_t **out, char const *internal_name); int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char const *proto_dir); -int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename); +int fr_dict_read(fr_dict_t const *dict, char const *dict_dir, char const *filename); /** @} */ /** @name Autoloader interface diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index 017587f94ae..95edf7650ad 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -2401,8 +2401,9 @@ int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char co * - 0 on success. * - -1 on failure. */ -int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename) +int fr_dict_read(fr_dict_t const *dict, char const *dir, char const *filename) { + fr_dict_t *mutable; INTERNAL_IF_NULL(dict, -1); if (!dict->attributes_by_name) { @@ -2410,7 +2411,8 @@ int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename) return -1; } - return dict_from_file(dict, dir, filename, NULL, 0); + memcpy(&mutable, &dict, sizeof(dict)); + return dict_from_file(mutable, dir, filename, NULL, 0); } /* diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index a7fe0854fa6..833de6a4877 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -851,7 +851,7 @@ int dict_attr_add_by_name(fr_dict_t *dict, fr_dict_attr_t *da) /** Add an attribute to the dictionary * - * @param[in] dict of protocol context we're operating in. + * @param[in] const_dict of protocol context we're operating in. * If NULL the internal dictionary will be used. * @param[in] parent to add attribute under. * @param[in] name of the attribute. @@ -862,13 +862,16 @@ int dict_attr_add_by_name(fr_dict_t *dict, fr_dict_attr_t *da) * - 0 on success. * - -1 on failure. */ -int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, +int fr_dict_attr_add(fr_dict_t const *const_dict, fr_dict_attr_t const *parent, char const *name, int attr, fr_type_t type, fr_dict_attr_flags_t const *flags) { fr_dict_attr_t *n; fr_dict_attr_t const *old; fr_dict_attr_t *mutable; fr_dict_attr_flags_t our_flags = *flags; + fr_dict_t *dict; + + memcpy(&dict, &const_dict, sizeof(const_dict)); /* const issues */ /* * Check that the definition is valid. @@ -2355,14 +2358,17 @@ int fr_dict_autoload(fr_dict_autoload_t const *to_load) */ void fr_dict_autofree(fr_dict_autoload_t const *to_free) { - fr_dict_t **dict; + fr_dict_t const **dict; fr_dict_autoload_t const *p; for (p = to_free; p->out; p++) { + fr_dict_t **mutable; dict = p->out; if (!*dict) continue; - fr_dict_free(dict); + memcpy(&mutable, &dict, sizeof(dict)); /* const issues */ + + fr_dict_free(mutable); } }