]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
empty lists are equal when compared via ==
authorAlan T. DeKok <aland@freeradius.org>
Wed, 11 Oct 2023 14:06:20 +0000 (10:06 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 11 Oct 2023 14:06:20 +0000 (10:06 -0400)
src/lib/util/calc.c
src/tests/keywords/cmp-list-empty [new file with mode: 0644]

index 9fbd6d6936f330f42b44f5764755f4469c616219..5f0c2d2e4deb21c2d43e120e99c69fda4cc36279 100644 (file)
@@ -2527,6 +2527,25 @@ int fr_value_calc_list_cmp(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_li
                op = T_OP_CMP_EQ;
        }
 
+       /*
+        *      Both lists are empty, they should be equal when checked for equality.
+        */
+       if ((fr_value_box_list_num_elements(list1) == 0) &&
+           (fr_value_box_list_num_elements(list2) == 0)) {
+               switch (op) {
+               case T_OP_CMP_EQ:
+               case T_OP_LE:
+               case T_OP_GE:
+                       invert = !invert;
+                       break;
+
+               default:
+                       break;
+               }
+
+               goto done;
+       }
+
        /*
         *      Emulate v3.  :(
         */
@@ -2550,8 +2569,9 @@ int fr_value_calc_list_cmp(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_li
        }
 
        /*
-        *      No match.
+        *      No match,
         */
+done:
        fr_value_box_clear(dst);
        fr_value_box_init(dst, FR_TYPE_BOOL, NULL, false); // @todo - add enum!
        dst->vb_bool = invert;
diff --git a/src/tests/keywords/cmp-list-empty b/src/tests/keywords/cmp-list-empty
new file mode 100644 (file)
index 0000000..9fd60e9
--- /dev/null
@@ -0,0 +1,45 @@
+#
+#  Test empty lists, or xlat failures.
+#
+#      {} == {} --> true
+#
+if !(%test.fail() == %test.fail()) {
+       test_fail
+}
+
+#
+#      {} != {} --> false
+#
+if (%test.fail() != %test.fail()) {
+       test_fail
+}
+
+#
+#      {} <= {} --> true
+#
+if !(%test.fail() <= %test.fail()) {
+       test_fail
+}
+
+#
+#      {} < {} --> false
+#
+if (%test.fail() < %test.fail()) {
+       test_fail
+}
+
+#
+#      {} >= {} --> true
+#
+if !(%test.fail() >= %test.fail()) {
+       test_fail
+}
+
+#
+#      {} > {} --> false
+#
+if (%test.fail() > %test.fail()) {
+       test_fail
+}
+
+success