diff options
author | Björn-Egil Dahlberg <[email protected]> | 2012-12-12 15:29:08 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2012-12-12 15:29:08 +0100 |
commit | 079411c887aa0971215ccb366fb83d7e56ec7777 (patch) | |
tree | 6e6a174d6fc6866c36c2c4a9d7c6f73fb83aba75 /erts/emulator/beam/bif.c | |
parent | 17532edb1301f52c1dbc37955a527bb1da333b4d (diff) | |
parent | 9c3451fdca9598772572f59bb594245e1c78137e (diff) | |
download | otp-079411c887aa0971215ccb366fb83d7e56ec7777.tar.gz otp-079411c887aa0971215ccb366fb83d7e56ec7777.tar.bz2 otp-079411c887aa0971215ccb366fb83d7e56ec7777.zip |
Merge branch 'egil/enforce-tuple-specification-size/OTP-10633'
* egil/enforce-tuple-specification-size/OTP-10633:
erts: Use memcpy instead of while in setelement/3
test: Refactor away ?line macro in tuple_SUITE
erts: Enforce tuple max size on BIFs
erts: Define max tuple size to 24 bits
Diffstat (limited to 'erts/emulator/beam/bif.c')
-rw-r--r-- | erts/emulator/beam/bif.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c index 98dc9a3902..c4ff4fe982 100644 --- a/erts/emulator/beam/bif.c +++ b/erts/emulator/beam/bif.c @@ -2421,9 +2421,7 @@ BIF_RETTYPE setelement_3(BIF_ALIST_3) /* copy the tuple */ resp = hp; - while (size--) { /* XXX use memcpy? */ - *hp++ = *ptr++; - } + sys_memcpy(hp, ptr, sizeof(Eterm)*size); resp[ix] = BIF_ARG_3; BIF_RET(make_tuple(resp)); } @@ -2436,7 +2434,7 @@ BIF_RETTYPE make_tuple_2(BIF_ALIST_2) Eterm* hp; Eterm res; - if (is_not_small(BIF_ARG_1) || (n = signed_val(BIF_ARG_1)) < 0) { + if (is_not_small(BIF_ARG_1) || (n = signed_val(BIF_ARG_1)) < 0 || n > ERTS_MAX_TUPLE_SIZE) { BIF_ERROR(BIF_P, BADARG); } hp = HAlloc(BIF_P, n+1); @@ -2457,7 +2455,7 @@ BIF_RETTYPE make_tuple_3(BIF_ALIST_3) Eterm list = BIF_ARG_3; Eterm* tup; - if (is_not_small(BIF_ARG_1) || (n = signed_val(BIF_ARG_1)) < 0) { + if (is_not_small(BIF_ARG_1) || (n = signed_val(BIF_ARG_1)) < 0 || n > ERTS_MAX_TUPLE_SIZE) { error: BIF_ERROR(BIF_P, BADARG); } @@ -2509,11 +2507,16 @@ BIF_RETTYPE append_element_2(BIF_ALIST_2) Eterm res; if (is_not_tuple(BIF_ARG_1)) { + error: BIF_ERROR(BIF_P, BADARG); } - ptr = tuple_val(BIF_ARG_1); + ptr = tuple_val(BIF_ARG_1); arity = arityval(*ptr); - hp = HAlloc(BIF_P, arity + 2); + + if (arity + 1 > ERTS_MAX_TUPLE_SIZE) + goto error; + + hp = HAlloc(BIF_P, arity + 2); res = make_tuple(hp); *hp = make_arityval(arity+1); while (arity--) { @@ -3097,7 +3100,7 @@ BIF_RETTYPE list_to_tuple_1(BIF_ALIST_1) Eterm* hp; int len; - if ((len = list_length(list)) < 0) { + if ((len = list_length(list)) < 0 || len > ERTS_MAX_TUPLE_SIZE) { BIF_ERROR(BIF_P, BADARG); } |