From 0e3abd29945b6d6a4f89892445f4d85bcb1d1e92 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Tue, 29 Nov 2022 12:53:33 -0500 Subject: Lua: Fix bad bitshift in lua_strx2number() The port of lua to OpenZFS modified lua to use int64_t for numbers instead of double. As part of this, a function for calculating exponentiation was replaced with a bit shift. Unfortunately, it did not handle negative values. Also, it only supported exponents numbers with 7 digits before before overflow. This supports exponents up to 15 digits before overflow. Clang's static analyzer reported this as "Result of operation is garbage or undefined" because the exponent was negative. Reviewed-by: Damian Szuberski Reviewed-by: Brian Behlendorf Signed-off-by: Richard Yao Closes #14204 --- module/lua/lobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/lua/lobject.c b/module/lua/lobject.c index 024d3199f..5d88d36c5 100644 --- a/module/lua/lobject.c +++ b/module/lua/lobject.c @@ -144,7 +144,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { *endptr = cast(char *, s); /* valid up to here */ ret: if (neg) r = -r; - return (r * (1 << e)); + return ((e >= 0) ? (r * (1ULL << e)) : (r / (1ULL << -e))); } #endif -- cgit v1.2.3