Skip to content

Commit

Permalink
Lua: Fix bad bitshift in lua_strx2number()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryao authored Nov 29, 2022
1 parent d6df444 commit 587a39b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion module/lua/lobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 587a39b

Please sign in to comment.