]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Lua: Fix bad bitshift in lua_strx2number()
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Tue, 29 Nov 2022 17:53:33 +0000 (12:53 -0500)
committerGitHub <noreply@github.com>
Tue, 29 Nov 2022 17:53:33 +0000 (09:53 -0800)
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 <szuberskidamian@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14204

module/lua/lobject.c

index f74dacdf5faff74a3887a69c5e889728567c9e94..ea1f9a8e3b9208f5d2762e800ba37049612069c1 100644 (file)
@@ -143,7 +143,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