]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
don't do upcasts on left shift and right shift.
authorAlan T. DeKok <aland@freeradius.org>
Thu, 10 Feb 2022 00:40:06 +0000 (19:40 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 10 Feb 2022 00:40:06 +0000 (19:40 -0500)
src/lib/util/calc.c

index 95f446b48fb96a8ec60026dc360aad3d827a9eda..88b989c14c941b7f089fcfe1f5e69dcf349ee4c1 100644 (file)
@@ -1501,6 +1501,19 @@ static int calc_integer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t con
                return calc_integer_type[dst->type](ctx, dst, in1, op, in2);
        }
 
+       /*
+        *      We don't do upcasts on shifting.
+        *
+        *      @todo - on left shift, if the RHS shift value is
+        *      larger than the LHS data type, then promote the result
+        *      data type to the next thing which will fit.
+        */
+       if ((op == T_RSHIFT) || (op == T_LSHIFT)) {
+               type = a->type;
+               fr_assert(b->type == FR_TYPE_UINT32);
+               goto calc_it;
+       }
+
        /*
         *      Upcast to the largest type which will handle the
         *      calculations.
@@ -1550,6 +1563,7 @@ static int calc_integer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t con
         *      Apparently putting the function pointer into an
         *      intermediate variable shuts it up.
         */
+calc_it:
        calc = calc_integer_type[type];
        if (!calc) return invalid_type(type);