aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_bif_re.c
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2011-05-06 12:28:13 +0200
committerBjörn Gustavsson <[email protected]>2011-05-10 11:05:59 +0200
commit6db87840174c80225bac5328ffe5e74dad5242f2 (patch)
tree139f3a2c43c2a635bb3878345dceb7d2cd077d4d /erts/emulator/beam/erl_bif_re.c
parent61c3d766889c79e3d3b95e8eb3da8638a2eccbd8 (diff)
downloadotp-6db87840174c80225bac5328ffe5e74dad5242f2.tar.gz
otp-6db87840174c80225bac5328ffe5e74dad5242f2.tar.bz2
otp-6db87840174c80225bac5328ffe5e74dad5242f2.zip
Replace io_list_len() with erts_iolist_size()
The io_list_len() function returns an int, where a negative return value indicates a type error. One problem is that an int only consists of 32 bits in a 64-bit emulator. Changing the return type to Sint will solve that problem, but in the 32-bit emulator, a large iolist and a iolist with a type error will both return a negative number. (Noticed by Jon Meredith.) Another problem is that for iolists whose total size exceed the word size, the result would be truncated, leading to a subsequent buffer overflow and emulator crash. Therefore, introduce the new erts_iolist_size() function which returns a status indication and writes the result size through a passed pointer. If the result size does not fit in a word, return an overflow indication.
Diffstat (limited to 'erts/emulator/beam/erl_bif_re.c')
-rw-r--r--erts/emulator/beam/erl_bif_re.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/erts/emulator/beam/erl_bif_re.c b/erts/emulator/beam/erl_bif_re.c
index d4a8a3aaa7..26891c4348 100644
--- a/erts/emulator/beam/erl_bif_re.c
+++ b/erts/emulator/beam/erl_bif_re.c
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 2008-2010. All Rights Reserved.
+ * Copyright Ericsson AB 2008-2011. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -417,7 +417,7 @@ build_compile_result(Process *p, Eterm error_tag, pcre *result, int errcode, con
BIF_RETTYPE
re_compile_2(BIF_ALIST_2)
{
- int slen;
+ Uint slen;
char *expr;
pcre *result;
int errcode = 0;
@@ -444,7 +444,7 @@ re_compile_2(BIF_ALIST_2)
BIF_TRAP2(ucompile_trap_exportp, BIF_P, BIF_ARG_1, BIF_ARG_2);
}
- if ((slen = io_list_len(BIF_ARG_1)) < 0) {
+ if (erts_iolist_size(BIF_ARG_1, &slen)) {
BIF_ERROR(BIF_P,BADARG);
}
expr = erts_alloc(ERTS_ALC_T_RE_TMP_BUF, slen + 1);
@@ -795,8 +795,8 @@ build_capture(Eterm capture_spec[CAPSPEC_SIZE], const pcre *code)
memcpy(tmpb,ap->name,ap->len);
tmpb[ap->len] = '\0';
} else {
- int slen = io_list_len(val);
- if (slen < 0) {
+ Uint slen;
+ if (erts_iolist_size(val, &slen)) {
goto error;
}
if ((slen + 1) > tmpbsiz) {
@@ -851,7 +851,7 @@ re_run_3(BIF_ALIST_3)
const pcre *code_tmp;
RestartContext restart;
byte *temp_alloc = NULL;
- int slength;
+ Uint slength;
int startoffset = 0;
int options = 0, comp_options = 0;
int ovsize;
@@ -875,7 +875,7 @@ re_run_3(BIF_ALIST_3)
if (is_not_tuple(BIF_ARG_2) || (arityval(*tuple_val(BIF_ARG_2)) != 4)) {
if (is_binary(BIF_ARG_2) || is_list(BIF_ARG_2) || is_nil(BIF_ARG_2)) {
/* Compile from textual RE */
- int slen;
+ Uint slen;
char *expr;
pcre *result;
int errcode = 0;
@@ -889,7 +889,7 @@ re_run_3(BIF_ALIST_3)
BIF_TRAP3(urun_trap_exportp, BIF_P, BIF_ARG_1, BIF_ARG_2, BIF_ARG_3);
}
- if ((slen = io_list_len(BIF_ARG_2)) < 0) {
+ if (erts_iolist_size(BIF_ARG_2, &slen)) {
BIF_ERROR(BIF_P,BADARG);
}
@@ -1027,7 +1027,7 @@ re_run_3(BIF_ALIST_3)
restart.flags |= RESTART_FLAG_SUBJECT_IN_BINARY;
} else {
handle_iolist:
- if ((slength = io_list_len(BIF_ARG_1)) < 0) {
+ if (erts_iolist_size(BIF_ARG_1, &slength)) {
erts_free(ERTS_ALC_T_RE_SUBJECT, restart.ovector);
erts_free(ERTS_ALC_T_RE_SUBJECT, restart.code);
if (restart.ret_info != NULL) {