diff options
author | daurnimator <quae@daurnimator.com> | 2016-01-03 10:55:28 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2016-01-04 19:05:42 +1100 |
commit | f53625badddd6c75421e5d5132c4eac6ee6eb01d (patch) | |
tree | 3bf3a9b197b63f233c07fce5bdbb336eac1f4376 | |
parent | 59cc755e2a48b0d479480c09bf0b9893ffdfce36 (diff) | |
download | luaossl-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
-rw-r--r-- | src/openssl.c | 10 |
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) { | |||
1686 | BIGNUM **bn; | 1686 | BIGNUM **bn; |
1687 | const char *str; | 1687 | const char *str; |
1688 | size_t len, i; | 1688 | size_t len, i; |
1689 | _Bool neg, hex = 0; | 1689 | _Bool neg, hex; |
1690 | 1690 | ||
1691 | index = lua_absindex(L, index); | 1691 | index = lua_absindex(L, index); |
1692 | 1692 | ||
@@ -1696,17 +1696,17 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) { | |||
1696 | 1696 | ||
1697 | str = lua_tolstring(L, index, &len); | 1697 | str = lua_tolstring(L, index, &len); |
1698 | 1698 | ||
1699 | luaL_argcheck(L, len > 0 && *str, index, "invalid big number string"); | ||
1700 | |||
1701 | neg = (str[0] == '-'); | 1699 | neg = (str[0] == '-'); |
1700 | hex = (str[neg] == '0' && (str[neg+1] == 'x' || str[neg+1] == 'X')); | ||
1702 | 1701 | ||
1703 | if (str[neg] == '0' && (str[neg+1] == 'x' || str[neg+1] == 'X')) { | 1702 | if (hex) { |
1704 | hex = 1; | 1703 | luaL_argcheck(L, len > 2+(size_t)neg, index, "invalid hex string"); |
1705 | for (i = 2+neg; i < len; i++) { | 1704 | for (i = 2+neg; i < len; i++) { |
1706 | if (!isxdigit(str[i])) | 1705 | if (!isxdigit(str[i])) |
1707 | luaL_argerror(L, 1, "invalid hex string"); | 1706 | luaL_argerror(L, 1, "invalid hex string"); |
1708 | } | 1707 | } |
1709 | } else { | 1708 | } else { |
1709 | luaL_argcheck(L, len > neg, index, "invalid decimal string"); | ||
1710 | for (i = neg; i < len; i++) { | 1710 | for (i = neg; i < len; i++) { |
1711 | if (!isdigit(str[i])) | 1711 | if (!isdigit(str[i])) |
1712 | luaL_argerror(L, 1, "invalid decimal string"); | 1712 | luaL_argerror(L, 1, "invalid decimal string"); |