]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add 16-bit "safe" field
authorAlan T. DeKok <aland@freeradius.org>
Sun, 12 Dec 2021 14:21:06 +0000 (09:21 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 12 Dec 2021 16:42:47 +0000 (11:42 -0500)
which marks up value boxes as being safe for particular uses

src/lib/util/value.c
src/lib/util/value.h

index 3be71cd54cb70c7b1b3f5574bc2aea66a06316c3..0ae483f2fb0d83bea1a206efaef19762649af972 100644 (file)
@@ -659,6 +659,7 @@ static inline void fr_value_box_copy_meta(fr_value_box_t *dst, fr_value_box_t co
        dst->enumv = src->enumv;
        dst->type = src->type;
        dst->tainted = src->tainted;
+       dst->safe = src->safe;
        fr_dlist_entry_init(&dst->entry);
 }
 
@@ -5846,3 +5847,36 @@ void value_box_list_verify(char const *file, int line, fr_value_box_list_t const
 
        while ((vb = fr_dlist_next(list, vb))) value_box_verify(file, line, vb, talloced);
 }
+
+
+/** Mark a value-box as "safe", of a particular type.
+ *
+ *  Tainted data cannot be marked "safe".  And once data is marked
+ *  safe, it cannot be marked as a different type of "safe"
+ */
+int fr_value_box_mark_safe(fr_value_box_t *box, uint16_t safe)
+{
+       if (box->tainted) {
+               fr_strerror_const("Cannot mark data as 'safe' - it is 'tainted'");
+               return -1;
+       }
+
+       if (box->safe == safe) return 0;
+
+       if (box->safe != 0) {
+               fr_strerror_const("Data was already marked 'safe', of a different type");
+               return -1;
+       }
+
+       box->safe = safe;
+       return 0;
+}
+
+/** Mark a value-box as "unsafe"
+ *
+ *  This always succeeds, and there are no side effects.
+ */
+void fr_value_box_mark_unsafe(fr_value_box_t *box)
+{
+       box->safe = 0;
+}
index 873f63dc85b6222414f0d3f57162e4689a134461..9204a3e50f9a9c04e80411b79c047d6191b2d241 100644 (file)
@@ -154,6 +154,7 @@ struct value_box_s {
        fr_type_t               _CONST type;                    //!< Type of this value-box.
 
        bool                            tainted;                //!< i.e. did it come from an untrusted source
+       uint16_t                 _CONST safe;                   //!< more detailed safety
 
        fr_dict_attr_t const            *enumv;                 //!< Enumeration values.
 
@@ -709,6 +710,17 @@ int                fr_value_box_ipaddr(fr_value_box_t *dst, fr_dict_attr_t const *enumv,
 
 int            fr_value_unbox_ipaddr(fr_ipaddr_t *dst, fr_value_box_t *src);
 
+static inline CC_HINT(nonnull,always_inline) bool fr_value_box_is_safe(fr_value_box_t const *box, uint16_t safe)
+{
+       if (!safe) return false;
+
+       return (box->safe == safe);
+}
+
+int fr_value_box_mark_safe(fr_value_box_t *box, uint16_t safe) CC_HINT(nonnull);
+
+void fr_value_box_mark_unsafe(fr_value_box_t *box) CC_HINT(nonnull);
+
 /** @name Box to box copying
  *
  * @{