From: Alan T. DeKok Date: Thu, 10 Feb 2022 00:40:06 +0000 (-0500) Subject: don't do upcasts on left shift and right shift. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6178cc21c17340249caaf1e1428e614a8d2538a0;p=thirdparty%2Ffreeradius-server.git don't do upcasts on left shift and right shift. --- diff --git a/src/lib/util/calc.c b/src/lib/util/calc.c index 95f446b48f..88b989c14c 100644 --- a/src/lib/util/calc.c +++ b/src/lib/util/calc.c @@ -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);