From f76bddd36de9c881837dfb76c3edf913a566802c Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 25 Mar 2013 18:13:37 +0100 Subject: Calculation of term_spec size (initial and next) changed There seem to be some problem with realloc (core dump) so the calculation of the term_spec size needs to be "corrected". --- .../src/flex/megaco_flex_scanner_drv.flex.src | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'lib/megaco/src') 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 b96a69415d..a8ff86e528 100644 --- a/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src +++ b/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2009. 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 @@ -101,6 +101,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 @@ -746,7 +753,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) @@ -851,15 +858,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. @@ -951,6 +963,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) @@ -1735,7 +1750,7 @@ static int 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) ); -- cgit v1.2.3 From e20a7db2bba04777a54c8d92f873d8322455bb25 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 26 Mar 2013 16:39:16 +0100 Subject: Ensure of incorrect number of terms when scanning property groups At the end of the mfs_load_property_groups function, the final property group list and property groups list is "terminated". A call to mfs_ensure_term_spec with (incorrect) size 4 was made prior to this to ensure enough data was available. The correct size was 6! --- lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/megaco/src') 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 a8ff86e528..efe817b92d 100644 --- a/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src +++ b/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src @@ -103,10 +103,12 @@ typedef struct { /* IBL = In Buffer Length - the raw (un-decoded) message buffer length */ #define TERM_SPEC_SIZE_INITIAL(IBL) (1024 + 2*(IBL)) +// #define TERM_SPEC_SIZE_INITIAL(IBL) (1000 + (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)) +// #define TERM_SPEC_SIZE_NEXT(CTSS,S) (2*(CTSS) + (S)) #if !defined(MEGACO_REENTRANT_FLEX_SCANNER) static MfsErlDrvData mfs_drv_data; @@ -1265,7 +1267,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 */ -- cgit v1.2.3 From 6de586ffb9bbc60b15e64a0b9696140093b925f1 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 3 Apr 2013 11:14:57 +0200 Subject: Removed comments --- lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/megaco/src') 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 efe817b92d..3520c34d50 100644 --- a/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src +++ b/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src @@ -103,12 +103,10 @@ typedef struct { /* IBL = In Buffer Length - the raw (un-decoded) message buffer length */ #define TERM_SPEC_SIZE_INITIAL(IBL) (1024 + 2*(IBL)) -// #define TERM_SPEC_SIZE_INITIAL(IBL) (1000 + (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)) -// #define TERM_SPEC_SIZE_NEXT(CTSS,S) (2*(CTSS) + (S)) #if !defined(MEGACO_REENTRANT_FLEX_SCANNER) static MfsErlDrvData mfs_drv_data; -- cgit v1.2.3