From: Alan T. DeKok Date: Tue, 25 Oct 2022 20:33:34 +0000 (-0400) Subject: upcast to 64-bits for integers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af2475566e02b6062732380c495a3c9218b8d5fd;p=thirdparty%2Ffreeradius-server.git upcast to 64-bits for integers --- diff --git a/src/lib/util/calc.c b/src/lib/util/calc.c index bb3a751e5c0..a0aa718a7ff 100644 --- a/src/lib/util/calc.c +++ b/src/lib/util/calc.c @@ -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); diff --git a/src/tests/xlat/expr.txt b/src/tests/xlat/expr.txt index 40464fafa57..b4440addbfc 100644 --- a/src/tests/xlat/expr.txt +++ b/src/tests/xlat/expr.txt @@ -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