aboutsummaryrefslogtreecommitdiffstats
path: root/lib/megaco/src/flex
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2013-04-17 14:19:29 +0200
committerMicael Karlberg <[email protected]>2013-04-17 14:19:29 +0200
commit10ca34488869c17cbd2d1a14ede4f4a8af67726e (patch)
tree9a1e29a244841f30713efd252a400f6b06740b9b /lib/megaco/src/flex
parent98bad864871eada14c948d27be9998bed36e2f50 (diff)
parentf3262e19759cebd3a602ef3124c01cbca4683ad8 (diff)
downloadotp-10ca34488869c17cbd2d1a14ede4f4a8af67726e.tar.gz
otp-10ca34488869c17cbd2d1a14ede4f4a8af67726e.tar.bz2
otp-10ca34488869c17cbd2d1a14ede4f4a8af67726e.zip
Merge branch 'bmk/megaco/flex_buffer_overrun_while_scanning_prop_parms/OTP-10998/r14' into bmk/megaco/flex_buffer_overrun_while_scanning_prop_parms/OTP-10998/r15
Conflicts: lib/megaco/.gitignore lib/megaco/doc/src/notes.xml lib/megaco/src/app/megaco.appup.src lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src lib/megaco/test/megaco_codec_v2_test.erl lib/megaco/vsn.mk
Diffstat (limited to 'lib/megaco/src/flex')
-rw-r--r--lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src33
-rw-r--r--lib/megaco/src/flex/megaco_flex_scanner_handler.erl6
2 files changed, 30 insertions, 9 deletions
diff --git a/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src b/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src
index b8146c345d..e143450ea9 100644
--- a/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src
+++ b/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src
@@ -1,8 +1,14 @@
/*
* %CopyrightBegin%
+<<<<<<< HEAD
*
* Copyright Ericsson AB 2001-2011. All Rights Reserved.
*
+=======
+ *
+ * Copyright Ericsson AB 2001-2013. All Rights Reserved.
+ *
+>>>>>>> bmk/megaco/flex_buffer_overrun_while_scanning_prop_parms/OTP-10998/r14
* 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
* compliance with the License. You should have received a copy of the
@@ -94,6 +100,13 @@ typedef struct {
int token_counter;
} MfsErlDrvData;
+/* IBL = In Buffer Length - the raw (un-decoded) message buffer length */
+#define TERM_SPEC_SIZE_INITIAL(IBL) (1024 + 2*(IBL))
+
+/* CTSS = Current term spec size - the current term spec length */
+/* S = Size - how many positions we need */
+#define TERM_SPEC_SIZE_NEXT(CTSS,S) ((CTSS) + 1024 + (S))
+
#if !defined(MEGACO_REENTRANT_FLEX_SCANNER)
static MfsErlDrvData mfs_drv_data;
#endif
@@ -736,7 +749,7 @@ v LOAD_TOKEN(mfs_VersionToken);
#endif
-/* #define MFS_DEBUG true */ /* temporary */
+// #define MFS_DEBUG true
#if defined(MFS_DEBUG)
# define DBG( proto ) printf proto
# define DBG_BUF(func, bufName, buf, bufSz) mfs_dbg_buf_print(func, bufName, buf, bufSz)
@@ -841,15 +854,20 @@ static void mfs_ensure_term_spec(MfsErlDrvData* dataP, int size)
"\n term_spec_size: %d\n",
dataP->term_spec_index, dataP->term_spec_size) );
- dataP->term_spec_size = (dataP->term_spec_size * 2) + size;
+ dataP->term_spec_size = TERM_SPEC_SIZE_NEXT(dataP->term_spec_size, size);
DBG( ("mfs_ensure_term_spec -> "
- "term_spec is at 0x%X, new term_spec_size is %d\n",
- (unsigned int) dataP->term_spec, dataP->term_spec_size) );
+ "term_spec is at 0x%X, new term_spec_size is %d (%lu)\n",
+ (unsigned int) dataP->term_spec,
+ dataP->term_spec_size,
+ dataP->term_spec_size * sizeof(ErlDrvTermData)) );
tmp = REALLOC(dataP->term_spec,
dataP->term_spec_size * sizeof(ErlDrvTermData));
+ DBG( ("mfs_ensure_term_spec -> "
+ "realloc result: 0x%X\n", (unsigned int) tmp) );
+
if (tmp == NULL) {
/*
* Ouch, we did'nt get any new memory.
@@ -941,6 +959,9 @@ static void mfs_octet_load_token(ErlDrvTermData TokenTag, int is_empty)
ASSIGN_TERM_SPEC(dataP, ERL_DRV_TUPLE);
ASSIGN_TERM_SPEC(dataP, 3);
+
+ DBG( ("mfs_octet_load_token -> done\n") );
+
}
#if defined(MEGACO_REENTRANT_FLEX_SCANNER)
@@ -1240,7 +1261,7 @@ static void mfs_load_property_groups(MfsErlDrvData* dataP)
} // if ((yytext[i] != SP)...
} // while ...
- mfs_ensure_term_spec(dataP, 4); // 2 + 2 just in case
+ mfs_ensure_term_spec(dataP, 6); // 3 + 3 just in case
/* Make sure we actually have some groups */
@@ -1725,7 +1746,7 @@ static ErlDrvSSizeT mfs_control(ErlDrvData handle,
dataP->text_buf = tmp;
dataP->text_ptr = tmp;
- dataP->term_spec_size = 1000 + buf_len; /* OTP-4237 */
+ dataP->term_spec_size = TERM_SPEC_SIZE_INITIAL(buf_len);
DBG( ("mfs_control -> allocate term-spec buffer: "
"\n term_spec_size: %d\n", dataP->term_spec_size) );
diff --git a/lib/megaco/src/flex/megaco_flex_scanner_handler.erl b/lib/megaco/src/flex/megaco_flex_scanner_handler.erl
index 420202134e..28333ab1d0 100644
--- a/lib/megaco/src/flex/megaco_flex_scanner_handler.erl
+++ b/lib/megaco/src/flex/megaco_flex_scanner_handler.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2001-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2001-2013. 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
@@ -181,11 +181,11 @@ terminate(_Reason, _S) ->
%% Returns: {ok, NewState}
%%----------------------------------------------------------------------
-code_change({down, _Vsn}, #state{conf = Conf} = State, downgrade_to_pre_3_13_1) ->
+code_change({down, _Vsn}, #state{conf = Conf} = State, downgrade_to_pre_3_14_3) ->
NewPorts = bump_flex_scanner(Conf),
{ok, State#state{conf = {flex, NewPorts}}};
-code_change(_Vsn, #state{conf = Conf} = State, upgrade_from_pre_3_13_1) ->
+code_change(_Vsn, #state{conf = Conf} = State, upgrade_from_pre_3_14_2) ->
NewPorts = bump_flex_scanner(Conf),
{ok, State#state{conf = {flex, NewPorts}}};