From: Alan T. DeKok Date: Wed, 10 Dec 2025 14:42:07 +0000 (-0500) Subject: string / octets can have length=0 and no pointer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=162ab5b264dc9e20d11b8d33eed78fe4e817eda9;p=thirdparty%2Ffreeradius-server.git string / octets can have length=0 and no pointer 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) --- diff --git a/src/lib/util/value.c b/src/lib/util/value.c index c727094f555..c8d8a0a3b61 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -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;