aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-03 10:55:28 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-04 19:05:42 +1100
commitf53625badddd6c75421e5d5132c4eac6ee6eb01d (patch)
tree3bf3a9b197b63f233c07fce5bdbb336eac1f4376 /src
parent59cc755e2a48b0d479480c09bf0b9893ffdfce36 (diff)
downloadluaossl-f53625badddd6c75421e5d5132c4eac6ee6eb01d.tar.gz
luaossl-f53625badddd6c75421e5d5132c4eac6ee6eb01d.tar.bz2
luaossl-f53625badddd6c75421e5d5132c4eac6ee6eb01d.zip
bignum: Don't allow empty numbers/strings to pass
Previously, "-" would pass the len>0 check; and end up as "0" The `*str` check was redundant, the switch/case already ensures the object at the given stack index is a string
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 4ca8da7..dba7c75 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1686,7 +1686,7 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) {
BIGNUM **bn;
const char *str;
size_t len, i;
- _Bool neg, hex = 0;
+ _Bool neg, hex;
index = lua_absindex(L, index);
@@ -1696,17 +1696,17 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) {
str = lua_tolstring(L, index, &len);
- luaL_argcheck(L, len > 0 && *str, index, "invalid big number string");
-
neg = (str[0] == '-');
+ hex = (str[neg] == '0' && (str[neg+1] == 'x' || str[neg+1] == 'X'));
- if (str[neg] == '0' && (str[neg+1] == 'x' || str[neg+1] == 'X')) {
- hex = 1;
+ if (hex) {
+ luaL_argcheck(L, len > 2+(size_t)neg, index, "invalid hex string");
for (i = 2+neg; i < len; i++) {
if (!isxdigit(str[i]))
luaL_argerror(L, 1, "invalid hex string");
}
} else {
+ luaL_argcheck(L, len > neg, index, "invalid decimal string");
for (i = neg; i < len; i++) {
if (!isdigit(str[i]))
luaL_argerror(L, 1, "invalid decimal string");