]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
string / octets can have length=0 and no pointer
authorAlan T. DeKok <aland@freeradius.org>
Wed, 10 Dec 2025 14:42:07 +0000 (09:42 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 10 Dec 2025 15:12:34 +0000 (10:12 -0500)
in which case there isn't a need for the actual data.  The printing
and encoding routines already ignore the pointer when length=i=0

But we may want to re-visit that decision.

Also add a commented-out assertion that the pointer is NULL when
length==0.  This could perhaps be relaxed to check that the pointer
points to a NUL byte (string), or is a zero-length memory region
(octets)

src/lib/util/value.c

index c727094f555575df71dccace1cdeb777043ac85c..c8d8a0a3b61893ef631cb99179413445b5bec31d 100644 (file)
@@ -6797,6 +6797,14 @@ DIAG_ON(nonnull-compare)
 #endif
        switch (vb->type) {
        case FR_TYPE_STRING:
+               if (!vb->vb_length) {
+#if 0
+                       fr_fatal_assert_msg(!vb->vb_strvalue || (talloc_array_length(vb->vb_strvalue) == 1), "CONSISTENCY CHECK FAILED %s[%d]: fr_value_box_t strvalue field "
+                                           "wasn non-NULL, but length was %u", file, line, vb->vb_length);
+#endif
+                       break;
+               }
+
                fr_fatal_assert_msg(vb->vb_strvalue, "CONSISTENCY CHECK FAILED %s[%d]: fr_value_box_t strvalue field "
                                    "was NULL", file, line);
                fr_fatal_assert_msg(vb->vb_strvalue[vb->vb_length] == '\0',
@@ -6815,6 +6823,14 @@ DIAG_ON(nonnull-compare)
                break;
 
        case FR_TYPE_OCTETS:
+               if (!vb->vb_length) {
+#if 0
+                       fr_fatal_assert_msg(!vb->vb_octets || (talloc_array_length(vb->vb_octets) == 0), "CONSISTENCY CHECK FAILED %s[%d]: fr_value_box_t octets field "
+                                           "wasn non-NULL, but length was %u", file, line, vb->vb_length);
+#endif
+                       break;
+               }
+
                fr_fatal_assert_msg(vb->vb_octets, "CONSISTENCY CHECK FAILED %s[%d]: fr_value_box_t octets field "
                                    "was NULL", file, line);
                break;