diff options
author | Mikael Pettersson <[email protected]> | 2015-07-31 21:15:13 +0200 |
---|---|---|
committer | Mikael Pettersson <[email protected]> | 2015-07-31 21:15:13 +0200 |
commit | 2e61f98dd41ce7328aebc27debd78845afdc0dba (patch) | |
tree | 980c3970edfcea12dd88da03f9116d97c8ac389f /erts | |
parent | 98647fcc1632f60871adee20031e294e5d5b6eb0 (diff) | |
download | otp-2e61f98dd41ce7328aebc27debd78845afdc0dba.tar.gz otp-2e61f98dd41ce7328aebc27debd78845afdc0dba.tar.bz2 otp-2e61f98dd41ce7328aebc27debd78845afdc0dba.zip |
erts: fix binary_to_integer boundary case
erlang:binary_to_integer/1 and /2 fail to detect invalid
input consisting of a single + or - sign but nothing else.
For an input like <<"+">> they return 0, while list_to_integer/1
correctly signals a badarg for "+".
Fixed by checking if the input is empty after the initial +/-
sign processing.
Added a test case which fails without this fix but passes with it.
Thanks to "niku" for reporting the issue.
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/beam/big.c | 3 | ||||
-rw-r--r-- | erts/emulator/test/num_bif_SUITE.erl | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/erts/emulator/beam/big.c b/erts/emulator/beam/big.c index 044bf6a34e..15bcd44fb9 100644 --- a/erts/emulator/beam/big.c +++ b/erts/emulator/beam/big.c @@ -2618,6 +2618,9 @@ Eterm erts_chars_to_integer(Process *BIF_P, char *bytes, size--; } + if (size == 0) + goto bytebuf_to_integer_1_error; + if (size < SMALL_DIGITS && base <= 10) { /* * * Take shortcut if we know that all chars are '0' < b < '9' and diff --git a/erts/emulator/test/num_bif_SUITE.erl b/erts/emulator/test/num_bif_SUITE.erl index f07f79b83d..90b6a36262 100644 --- a/erts/emulator/test/num_bif_SUITE.erl +++ b/erts/emulator/test/num_bif_SUITE.erl @@ -429,7 +429,7 @@ t_string_to_integer(Config) when is_list(Config) -> list_to_binary(Value))), {'EXIT', {badarg, _}} = (catch erlang:list_to_integer(Value)) - end,["1.0"," 1"," -1",""]), + end,["1.0"," 1"," -1","","+"]), % Custom base error cases lists:foreach(fun({Value,Base}) -> |