diff options
author | Björn Gustavsson <[email protected]> | 2012-10-30 08:28:11 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2012-11-05 12:19:29 +0100 |
commit | 793dd44c6cdb892de9d1b44694fd4069726030cc (patch) | |
tree | bdb14c473ab065fccd2928254e8bc8aed5ea81bd /erts/emulator/beam | |
parent | e85c4dda93e416e8e97c0dcfadc5eeaf5bd8b4e1 (diff) | |
download | otp-793dd44c6cdb892de9d1b44694fd4069726030cc.tar.gz otp-793dd44c6cdb892de9d1b44694fd4069726030cc.tar.bz2 otp-793dd44c6cdb892de9d1b44694fd4069726030cc.zip |
Fix binary append exceptions
Code such as the following should cause an exception:
Bin = <<0:1>>,
<<Bin/binary,...>>
(Because the "binary" type implies that the binary must have a
size in bits that is a multiple of 8.)
Depending on the binary, either no exception was thrown or the
wrong exception was thrown (because c_p->freason was not set).
Noticed-by: Adam Rutkowski
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r-- | erts/emulator/beam/erl_bits.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/erts/emulator/beam/erl_bits.c b/erts/emulator/beam/erl_bits.c index 6bc227eeda..3753b618e1 100644 --- a/erts/emulator/beam/erl_bits.c +++ b/erts/emulator/beam/erl_bits.c @@ -1247,6 +1247,12 @@ erts_bs_append(Process* c_p, Eterm* reg, Uint live, Eterm build_size_term, */ erts_bin_offset = 8*sb->size + sb->bitsize; + if (unit > 1) { + if ((unit == 8 && (erts_bin_offset & 7) != 0) || + (erts_bin_offset % unit) != 0) { + goto badarg; + } + } used_size_in_bits = erts_bin_offset + build_size_in_bits; sb->is_writable = 0; /* Make sure that no one else can write. */ pb->size = NBYTES(used_size_in_bits); @@ -1316,6 +1322,12 @@ erts_bs_append(Process* c_p, Eterm* reg, Uint live, Eterm build_size_term, */ ERTS_GET_BINARY_BYTES(bin, src_bytes, bitoffs, bitsize); erts_bin_offset = 8*binary_size(bin) + bitsize; + if (unit > 1) { + if ((unit == 8 && (erts_bin_offset & 7) != 0) || + (erts_bin_offset % unit) != 0) { + goto badarg; + } + } used_size_in_bits = erts_bin_offset + build_size_in_bits; used_size_in_bytes = NBYTES(used_size_in_bits); bin_size = 2*used_size_in_bytes; @@ -1363,12 +1375,6 @@ erts_bs_append(Process* c_p, Eterm* reg, Uint live, Eterm build_size_term, /* * Now copy the data into the binary. */ - if (unit > 1) { - if ((unit == 8 && (erts_bin_offset & 7) != 0) || - (erts_bin_offset % unit) != 0) { - return THE_NON_VALUE; - } - } copy_binary_to_buffer(erts_current_bin, 0, src_bytes, bitoffs, erts_bin_offset); return make_binary(sb); |