diff --git a/0001-scanner-fix-default-of-yy_top_state.patch b/0001-scanner-fix-default-of-yy_top_state.patch new file mode 100644 index 0000000000000000000000000000000000000000..56b5e59a11e8d101420c12cffa3754c1ad026cd1 --- /dev/null +++ b/0001-scanner-fix-default-of-yy_top_state.patch @@ -0,0 +1,28 @@ +From 67b3e448727da3093cdc6f0ca7fd151fbf3c10ad Mon Sep 17 00:00:00 2001 +From: jannick0 +Date: Sun, 7 Jan 2018 21:34:32 +0100 +Subject: [PATCH] scanner: fix default of yy_top_state() + +For an _empty_ state stack the top of the state stack defaults to the state as if no state stack were present. + +NB: sanity check for `yy_start_stack_ptr` could be added in `yy_top_state()`. +--- + src/flex.skl | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/flex.skl b/src/flex.skl +index 1043238..05729df 100644 +--- a/src/flex.skl ++++ b/src/flex.skl +@@ -2465,7 +2465,7 @@ m4_ifdef( [[M4_YY_NO_TOP_STATE]],, + %endif + { + M4_YY_DECL_GUTS_VAR(); +- return YY_G(yy_start_stack)[YY_G(yy_start_stack_ptr) - 1]; ++ return yy_start_stack_ptr > 0 ? YY_G(yy_start_stack)[YY_G(yy_start_stack_ptr) - 1] : YY_START; + } + ]]) + +-- +1.8.3.1 + diff --git a/0002-scanner-fix-default-of-yy_top_state.patch b/0002-scanner-fix-default-of-yy_top_state.patch new file mode 100644 index 0000000000000000000000000000000000000000..627cff66a9dbc64ff7d30b0a207aa267adf12cbc --- /dev/null +++ b/0002-scanner-fix-default-of-yy_top_state.patch @@ -0,0 +1,26 @@ +From 3971b6146aab12e1c54945dcb47ae92a25a3f3c3 Mon Sep 17 00:00:00 2001 +From: jannick0 +Date: Mon, 8 Jan 2018 10:04:23 +0100 +Subject: [PATCH] scanner: fix default of yy_top_state() + +extend fix when `YY_G` is used (reentrant scanner). +--- + src/flex.skl | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/flex.skl b/src/flex.skl +index 05729df..d9cdcc0 100644 +--- a/src/flex.skl ++++ b/src/flex.skl +@@ -2465,7 +2465,7 @@ m4_ifdef( [[M4_YY_NO_TOP_STATE]],, + %endif + { + M4_YY_DECL_GUTS_VAR(); +- return yy_start_stack_ptr > 0 ? YY_G(yy_start_stack)[YY_G(yy_start_stack_ptr) - 1] : YY_START; ++ return YY_G(yy_start_stack_ptr) > 0 ? YY_G(yy_start_stack)[YY_G(yy_start_stack_ptr) - 1] : YY_START; + } + ]]) + +-- +1.8.3.1 + diff --git a/build-AC_USE_SYSTEM_EXTENSIONS-in-configure.ac.patch b/build-AC_USE_SYSTEM_EXTENSIONS-in-configure.ac.patch new file mode 100644 index 0000000000000000000000000000000000000000..3d7807d1712813a8c824995eb66ab763ce6f90eb --- /dev/null +++ b/build-AC_USE_SYSTEM_EXTENSIONS-in-configure.ac.patch @@ -0,0 +1,32 @@ +From 24fd0551333e7eded87b64dd36062da3df2f6380 Mon Sep 17 00:00:00 2001 +From: Explorer09 +Date: Mon, 4 Sep 2017 10:47:33 +0800 +Subject: [PATCH] build: AC_USE_SYSTEM_EXTENSIONS in configure.ac. + +This would, e.g. define _GNU_SOURCE in config.h, enabling the +reallocarray() prototype in glibc 2.26+ on Linux systems with that +version of glibc. + +Fixes #241. +--- + configure.ac | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/configure.ac b/configure.ac +index c6f12d6..3c977a4 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -25,8 +25,10 @@ + # autoconf requirements and initialization + + AC_INIT([the fast lexical analyser generator],[2.6.4],[flex-help@lists.sourceforge.net],[flex]) ++AC_PREREQ([2.60]) + AC_CONFIG_SRCDIR([src/scan.l]) + AC_CONFIG_AUX_DIR([build-aux]) ++AC_USE_SYSTEM_EXTENSIONS + LT_INIT + AM_INIT_AUTOMAKE([1.11.3 -Wno-portability foreign check-news std-options dist-lzip parallel-tests subdir-objects]) + AC_CONFIG_HEADER([src/config.h]) +-- +1.8.3.1 + diff --git a/filter-Output-correct-line-value-for-current-file.patch b/filter-Output-correct-line-value-for-current-file.patch new file mode 100644 index 0000000000000000000000000000000000000000..7849dccd0b64b449f1cf1e3a38f671e61095a3ea --- /dev/null +++ b/filter-Output-correct-line-value-for-current-file.patch @@ -0,0 +1,29 @@ +From 2c7e34bb958ac5d083b2bab4c89907cd0669196d Mon Sep 17 00:00:00 2001 +From: Jeff Smith +Date: Sat, 1 Apr 2017 01:18:12 -0500 +Subject: [PATCH] filter: Output correct #line value for current file. + +A #line pre-processor directive specifies the line number and source +file of the following lines. If the source file _is_ the current file, +the line number should be that of the line following the directive. So +the specified line number should be the current line number plus 1. +--- + src/filter.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/filter.c b/src/filter.c +index 71f3635..ed3bfe3 100644 +--- a/src/filter.c ++++ b/src/filter.c +@@ -391,7 +391,7 @@ int filter_fix_linedirs (struct filter *chain) + /* Adjust the line directives. */ + in_gen = true; + snprintf (buf, readsz, "#line %d \"%s\"\n", +- lineno, filename); ++ lineno + 1, filename); + } + else { + /* it's a #line directive for code we didn't write */ +-- +1.8.3.1 + diff --git a/filter-memory-leak-free-scanner-postprocessing.patch b/filter-memory-leak-free-scanner-postprocessing.patch new file mode 100644 index 0000000000000000000000000000000000000000..27e9a2f77d68742a49c1787d6ea27616204fb852 --- /dev/null +++ b/filter-memory-leak-free-scanner-postprocessing.patch @@ -0,0 +1,72 @@ +From 8a044dbe6d03877c3d8c205ae76be9c41f442237 Mon Sep 17 00:00:00 2001 +From: "viktor.shepel" +Date: Tue, 20 Jun 2017 17:03:42 +0300 +Subject: [PATCH] filter: memory leak free scanner postprocessing. + +**Issue:** +Scanner postprocessing leaks memory during correction of `#line` +directives values and generation of C header file. + +**Root cause:** +`filter_fix_linedirs` and `filter_tee_header` functions do not +dispose allocated memory. + +**Solution:** +Automatically reclaim affected memory by allocating it on stack +insted of heap. Stack allocation should not be a problem as its +only 512 bytes and there is no recursive calls. +--- + src/filter.c | 16 ++++------------ + 1 file changed, 4 insertions(+), 12 deletions(-) + +diff --git a/src/filter.c b/src/filter.c +index ed3bfe3..35b80a9 100644 +--- a/src/filter.c ++++ b/src/filter.c +@@ -230,8 +230,7 @@ int filter_tee_header (struct filter *chain) + * header file at the same time. + */ + +- const int readsz = 512; +- char *buf; ++ char buf[512]; + int to_cfd = -1; + FILE *to_c = NULL, *to_h = NULL; + bool write_header; +@@ -283,10 +282,7 @@ int filter_tee_header (struct filter *chain) + fprintf (to_c, "m4_define( [[M4_YY_OUTFILE_NAME]],[[%s]])m4_dnl\n", + outfilename ? outfilename : ""); + +- buf = malloc((size_t) readsz); +- if (!buf) +- flexerror(_("malloc failed in filter_tee_header")); +- while (fgets (buf, readsz, stdin)) { ++ while (fgets (buf, sizeof buf, stdin)) { + fputs (buf, to_c); + if (write_header) + fputs (buf, to_h); +@@ -336,8 +332,8 @@ int filter_tee_header (struct filter *chain) + */ + int filter_fix_linedirs (struct filter *chain) + { +- char *buf; +- const size_t readsz = 512; ++ char buf[512]; ++ const size_t readsz = sizeof buf; + int lineno = 1; + bool in_gen = true; /* in generated code */ + bool last_was_blank = false; +@@ -345,10 +341,6 @@ int filter_fix_linedirs (struct filter *chain) + if (!chain) + return 0; + +- buf = malloc(readsz); +- if (!buf) +- flexerror(_("malloc failed in filter_fix_linedirs")); +- + while (fgets (buf, (int) readsz, stdin)) { + + regmatch_t m[10]; +-- +1.8.3.1 + diff --git a/flex-2.6.1.tar.xz b/flex-2.6.1.tar.xz deleted file mode 100644 index fd897a909ba23c812f6b6a26352557ce904649e1..0000000000000000000000000000000000000000 Binary files a/flex-2.6.1.tar.xz and /dev/null differ diff --git a/flex-2.6.4.tar.gz b/flex-2.6.4.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..fd328f959c8d1f111fcb5dae9ca377f2e60c238c Binary files /dev/null and b/flex-2.6.4.tar.gz differ diff --git a/flex.spec b/flex.spec index 9cf45bb7d07fd8a5a33a5bbbb5232e7597380f69..b52d635db9b1190383b48caa2a533725c2ab06e6 100644 --- a/flex.spec +++ b/flex.spec @@ -1,12 +1,24 @@ Name: flex -Version: 2.6.1 -Release: 13 +Version: 2.6.4 +Release: 2 Summary: A fast lexical analyzer generator License: BSD and LGPLv2+ URL: https://github.com/westes/flex -Source0: https://github.com/westes/flex/releases/download/v%{version}/flex-%{version}.tar.xz - -BuildRequires: gcc gettext help2man m4 bison +Source0: https://github.com/westes/flex/releases/download/v%{version}/flex-%{version}.tar.gz + +Patch0000: build-AC_USE_SYSTEM_EXTENSIONS-in-configure.ac.patch +Patch0001: filter-memory-leak-free-scanner-postprocessing.patch +Patch0002: scanner-c-i-j-should-preserve-case.patch +Patch0003: filter-Output-correct-line-value-for-current-file.patch +Patch0004: scanner-memory-leak-free-scanner-generator.patch +Patch0005: scanner-Ignore-comment-lines-in-skeleton-files.patch +Patch0006: mkskel.sh-fix-EOL-issue-for-CRLF-systems.patch +Patch0007: scanner-temporarily-protect-against-ccl-overflow-ove.patch +Patch0008: scanner-prevent-overflow-in-add_action.patch +Patch0009: 0001-scanner-fix-default-of-yy_top_state.patch +Patch0010: 0002-scanner-fix-default-of-yy_top_state.patch + +BuildRequires: gcc gettext help2man m4 bison texinfo Requires: m4 Requires(post): info Requires(preun): info @@ -36,9 +48,10 @@ Obsoletes: flex-doc Man pages and other related documents for %{name}. %prep -%autosetup -n %{name}-%{version} +%autosetup -n %{name}-%{version} -p1 %build +autoreconf %configure %make_build @@ -72,7 +85,7 @@ fi %dir %{_pkgdocdir} %license COPYING %{_pkgdocdir}/NEWS -%{_pkgdocdir}/README +%{_pkgdocdir}/README.md %{_bindir}/* %{_includedir}/FlexLexer.h %{_infodir}/flex.info* @@ -87,6 +100,15 @@ fi %{_mandir}/man1/* %changelog +* Sun Jun 28 2020 openEuler liuchengaung - 2.6.4-2 +- quality enhancement synchronization github patch + +* Mon May 11 2020 openEuler Buildteam - 2.6.4-1 +- Type:requirement +- ID:NA +- SUG:NA +- DESC:update to 2.6.4 + * Tue Jan 7 2020 chengquan - 2.6.1-13 - Type:enhancement - ID:NA diff --git a/mkskel.sh-fix-EOL-issue-for-CRLF-systems.patch b/mkskel.sh-fix-EOL-issue-for-CRLF-systems.patch new file mode 100644 index 0000000000000000000000000000000000000000..0ebcdb0e9ce387b9683a20c74c167fe79b892577 --- /dev/null +++ b/mkskel.sh-fix-EOL-issue-for-CRLF-systems.patch @@ -0,0 +1,25 @@ +From 3f2b9a4d630b702f6dd8592014f89d40a6a4bcc1 Mon Sep 17 00:00:00 2001 +From: Jannick +Date: Tue, 18 Jul 2017 02:03:30 +0200 +Subject: [PATCH] mkskel.sh: fix EOL issue for CRLF systems + +--- + src/mkskel.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/mkskel.sh b/src/mkskel.sh +index 1aa59e1..2d6ae9f 100755 +--- a/src/mkskel.sh ++++ b/src/mkskel.sh +@@ -48,7 +48,7 @@ sed '/^%#/d + s/m4_/m4preproc_/g + s/a4_/4_/g + s/[\\"]/\\&/g +-s/.*/ "&",/' ++s/[^\r]*/ "&",/' + + echo ' 0 + };' +-- +1.8.3.1 + diff --git a/scanner-Ignore-comment-lines-in-skeleton-files.patch b/scanner-Ignore-comment-lines-in-skeleton-files.patch new file mode 100644 index 0000000000000000000000000000000000000000..59ffbcbf8ede1ccfa2a0756a42dc4448de2f049a --- /dev/null +++ b/scanner-Ignore-comment-lines-in-skeleton-files.patch @@ -0,0 +1,34 @@ +From 7af066b952fc81eb1a29079c7206e50ffed80c40 Mon Sep 17 00:00:00 2001 +From: jannick0 +Date: Sun, 9 Jul 2017 22:36:14 +0200 +Subject: [PATCH] scanner: Ignore comment lines in skeleton files. + +In skeleton files comments are indicated by leading `%#` and when +directly read in using `flex -S ` they should be +ignored. Example: `flex.skl`. + +Amending commit 2f21edac99b5efc432417233e6e53326d630e08f which removed +this conditional branch. +--- + src/misc.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/src/misc.c b/src/misc.c +index 39483ea..9ead263 100644 +--- a/src/misc.c ++++ b/src/misc.c +@@ -732,7 +732,10 @@ void skelout (void) + */ + #define cmd_match(s) (strncmp(buf,(s),strlen(s))==0) + +- if (buf[1] == '%') { ++ if (buf[1] == '#') { ++ /* %# indicates comment line to be ignored */ ++ } ++ else if (buf[1] == '%') { + /* %% is a break point for skelout() */ + return; + } +-- +1.8.3.1 + diff --git a/scanner-c-i-j-should-preserve-case.patch b/scanner-c-i-j-should-preserve-case.patch new file mode 100644 index 0000000000000000000000000000000000000000..acb0257d270161aafb7a51126ded20c7dee1f487 --- /dev/null +++ b/scanner-c-i-j-should-preserve-case.patch @@ -0,0 +1,26 @@ +From ea4b0a129eebedba73eb08eb2639040fd758c51f Mon Sep 17 00:00:00 2001 +From: NieDzejkob +Date: Thu, 29 Jun 2017 12:38:25 +0200 +Subject: [PATCH] scanner: c{i,j} should preserve case. + +Fixes #193 +--- + src/nfa.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/nfa.c b/src/nfa.c +index 9143cf6..3d9bf24 100644 +--- a/src/nfa.c ++++ b/src/nfa.c +@@ -499,6 +499,8 @@ int mkor (int first, int second) + } + } + ++ firstst[first] = MIN(firstst[first], firstst[second]); ++ + finalst[first] = orend; + return first; + } +-- +1.8.3.1 + diff --git a/scanner-memory-leak-free-scanner-generator.patch b/scanner-memory-leak-free-scanner-generator.patch new file mode 100644 index 0000000000000000000000000000000000000000..391fbbcc4d8dbbaef3538b53c7979c4ab887a39c --- /dev/null +++ b/scanner-memory-leak-free-scanner-generator.patch @@ -0,0 +1,100 @@ +From faa877a8434a1d2f1b2ab5315eee6ca44dc79629 Mon Sep 17 00:00:00 2001 +From: "viktor.shepel" +Date: Tue, 20 Jun 2017 18:22:53 +0300 +Subject: [PATCH] scanner: memory leak free scanner generator. + +**Issue:** +Scanner generation leaks memory for transition tables when invoked +without `--tables-file` option. + +**Root cause:** +`gentabs` function has different memory acquire/release conditions. + +**Solution:** +Reclaim memory at the same scope where it was alloacated. +--- + src/gen.c | 27 +++++++++++++-------------- + 1 file changed, 13 insertions(+), 14 deletions(-) + +diff --git a/src/gen.c b/src/gen.c +index 590e5d8..ec0e014 100644 +--- a/src/gen.c ++++ b/src/gen.c +@@ -1234,9 +1234,9 @@ void gentabs (void) + yytbl_data_compress (yyacc_tbl); + if (yytbl_data_fwrite (&tableswr, yyacc_tbl) < 0) + flexerror (_("Could not write yyacc_tbl")); +- yytbl_data_destroy (yyacc_tbl); +- yyacc_tbl = NULL; + } ++ yytbl_data_destroy (yyacc_tbl); ++ yyacc_tbl = NULL; + /* End generating yy_accept */ + + if (useecs) { +@@ -1289,11 +1289,10 @@ void gentabs (void) + if (tablesext) { + yytbl_data_compress (yymeta_tbl); + if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0) +- flexerror (_ +- ("Could not write yymeta_tbl")); +- yytbl_data_destroy (yymeta_tbl); +- yymeta_tbl = NULL; ++ flexerror (_("Could not write yymeta_tbl")); + } ++ yytbl_data_destroy (yymeta_tbl); ++ yymeta_tbl = NULL; + /* End generating yy_meta */ + } + +@@ -1350,9 +1349,9 @@ void gentabs (void) + yytbl_data_compress (yybase_tbl); + if (yytbl_data_fwrite (&tableswr, yybase_tbl) < 0) + flexerror (_("Could not write yybase_tbl")); +- yytbl_data_destroy (yybase_tbl); +- yybase_tbl = NULL; + } ++ yytbl_data_destroy (yybase_tbl); ++ yybase_tbl = NULL; + /* End generating yy_base */ + + +@@ -1382,9 +1381,9 @@ void gentabs (void) + yytbl_data_compress (yydef_tbl); + if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0) + flexerror (_("Could not write yydef_tbl")); +- yytbl_data_destroy (yydef_tbl); +- yydef_tbl = NULL; + } ++ yytbl_data_destroy (yydef_tbl); ++ yydef_tbl = NULL; + /* End generating yy_def */ + + +@@ -1420,9 +1419,9 @@ void gentabs (void) + yytbl_data_compress (yynxt_tbl); + if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0) + flexerror (_("Could not write yynxt_tbl")); +- yytbl_data_destroy (yynxt_tbl); +- yynxt_tbl = NULL; + } ++ yytbl_data_destroy (yynxt_tbl); ++ yynxt_tbl = NULL; + /* End generating yy_nxt */ + + /* Begin generating yy_chk */ +@@ -1454,9 +1453,9 @@ void gentabs (void) + yytbl_data_compress (yychk_tbl); + if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0) + flexerror (_("Could not write yychk_tbl")); +- yytbl_data_destroy (yychk_tbl); +- yychk_tbl = NULL; + } ++ yytbl_data_destroy (yychk_tbl); ++ yychk_tbl = NULL; + /* End generating yy_chk */ + + free(acc_array); +-- +1.8.3.1 + diff --git a/scanner-prevent-overflow-in-add_action.patch b/scanner-prevent-overflow-in-add_action.patch new file mode 100644 index 0000000000000000000000000000000000000000..19bf23e43d28719c2f509c57f34ccbb46f2a0331 --- /dev/null +++ b/scanner-prevent-overflow-in-add_action.patch @@ -0,0 +1,34 @@ +From 23882383d45dcd37b5177835c873f4e1d9582db1 Mon Sep 17 00:00:00 2001 +From: Explorer09 +Date: Fri, 13 Oct 2017 16:59:26 +0800 +Subject: [PATCH] scanner: prevent overflow in add_action() + +--- + src/misc.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/src/misc.c b/src/misc.c +index fa33a5b..745e6a8 100644 +--- a/src/misc.c ++++ b/src/misc.c +@@ -116,15 +116,14 @@ void add_action (const char *new_text) + int len = (int) strlen (new_text); + + while (len + action_index >= action_size - 10 /* slop */ ) { +- int new_size = action_size * 2; + +- if (new_size <= 0) ++ if (action_size > INT_MAX / 2) + /* Increase just a little, to try to avoid overflow + * on 16-bit machines. + */ + action_size += action_size / 8; + else +- action_size = new_size; ++ action_size = action_size * 2; + + action_array = + reallocate_character_array (action_array, +-- +1.8.3.1 + diff --git a/scanner-temporarily-protect-against-ccl-overflow-ove.patch b/scanner-temporarily-protect-against-ccl-overflow-ove.patch new file mode 100644 index 0000000000000000000000000000000000000000..1b6231213bd898348cfe91313d4845d3f498d213 --- /dev/null +++ b/scanner-temporarily-protect-against-ccl-overflow-ove.patch @@ -0,0 +1,37 @@ +From 12d2f8608046c5d43646e3c1dc277c0a2914ae1b Mon Sep 17 00:00:00 2001 +From: Explorer09 +Date: Sat, 14 Oct 2017 00:31:01 +0800 +Subject: [PATCH] scanner: temporarily protect against ccl overflow & + overwriting. + +For ccladd(), if cclp given is a non-last ccl, adding a char into it +will overflow the buffer and overwrite the first char in the next ccl. + +For now, add a temporary detection and protection code. (Not sure if +this could happen in user input, but if it could, then you can expect +some "corrupted" behavior for generated scanners.) +--- + src/ccl.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/src/ccl.c b/src/ccl.c +index ff9a213..5c5af13 100644 +--- a/src/ccl.c ++++ b/src/ccl.c +@@ -73,6 +73,13 @@ void ccladd (int cclp, int ch) + + newpos = ind + len; + ++ /* For a non-last cclp, expanding the set will overflow and overwrite a ++ * char in the next cclp. ++ * FIXME: Need another allocation scheme for ccl's. */ ++ if (cclp != lastccl) { ++ flexfatal(_("internal error: trying to add a char to a non-last ccl.\n")); ++ } ++ + if (newpos >= current_max_ccl_tbl_size) { + current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT; + +-- +1.8.3.1 +