]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
upcast to 64-bits for integers
authorAlan T. DeKok <aland@freeradius.org>
Tue, 25 Oct 2022 20:33:34 +0000 (16:33 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 26 Oct 2022 16:31:00 +0000 (12:31 -0400)
src/lib/util/calc.c
src/tests/xlat/expr.txt

index bb3a751e5c049f97806c6b11a5de0183858c6a8d..a0aa718a7ffb85fd63d10471d2365c1cfbd5f5be 100644 (file)
@@ -1850,13 +1850,26 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint
                         *      @todo - the output type could be larger than the input type, if the shift is
                         *      more than the input type can handle.  e.g. uint8 << 4 could result in uint16
                         */
-               case T_RSHIFT:
                case T_LSHIFT:
+                       if (!fr_type_is_integer(a->type)) {
+                               return handle_result(a->type, T_LSHIFT, ERR_INVALID);
+                       }
+
+                       if (hint != FR_TYPE_NULL) break;
+
+                       if (fr_type_is_signed(a->type)) {
+                               hint = FR_TYPE_INT64;
+                               break;
+                       }
+                       hint = FR_TYPE_UINT64;
+                       break;
+
+               case T_RSHIFT:
                        hint = a->type;
                        break;
 
                default:
-                       return ERR_INVALID;
+                       return handle_result(a->type, T_LSHIFT, ERR_INVALID);
                }
        } while (0);
 
index 40464fafa57effe1e81605a9ae27fb2ba8c17942..b4440addbfc39f517a2049fcebea84496c0e108f 100644 (file)
@@ -45,17 +45,22 @@ match false
 xlat_expr &Packet-Src-IP-Address =~ /%{Packet-Dst-IP-Address}/
 match true
 
-# @todo - failure?
+# Auto upcast
 xlat_expr (uint32) 1 << 32
-match NULL
-#match ERROR expanding xlat: Value overflows 'uint32' when calculating result.
+match 4294967296
+
+#
+#  The error message is currently "eaten" by a call to RPEDEBUG
+#  in xlat_eval.c.  Oh well.
+#
+xlat_expr (uint32)((uint32) 1 << 32)
+match ERROR expanding xlat: 
 
 #
 #  This shifts it 8, and then tries to cast it to uint8?
 #
 xlat_expr (uint8) 1 << 8
-match NULL
-#match ERROR expanding xlat: Value overflows 'uint8' when calculating result.
+match 256
 
 # Cannot perform any operations for destination type ether
 xlat_expr 00:01:02:03:04:05 ^ 11:22:33:44:55:66