aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-03-22 13:11:14 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-03-22 13:16:24 +0200
commit03b7314673fc4030e933f86890aad7f82ec30eca (patch)
tree0e9e00ce9cfc5a52a2ff21c06f800b7b9879a22a
parentf91b19e696794204f2ba05587eb0dc0475c65345 (diff)
downloadcflow-03b7314673fc4030e933f86890aad7f82ec30eca.tar.gz
cflow-03b7314673fc4030e933f86890aad7f82ec30eca.tar.bz2
Properly handle invalid input
See https://savannah.gnu.org/bugs/?44113 * src/parser.c (cleanup_stack): Ignore negative deltas. (parse_function_declaration): Don't set caller if the symbol is in automatic storage. Note: that means nested function definitions can't be handled. * tests/invalid.at: New test case. * tests/Makefile.am: Add new test case. * tests/testsuite.at: Likewise.
-rw-r--r--.gitignore1
-rw-r--r--src/parser.c7
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/invalid.at34
-rw-r--r--tests/testsuite.at1
5 files changed, 42 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 60d871e..9039854 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@
13ABOUT-NLS 13ABOUT-NLS
14ChangeLog 14ChangeLog
15INSTALL 15INSTALL
16TAGS
16Makefile 17Makefile
17Makefile.in 18Makefile.in
18aclocal.m4 19aclocal.m4
diff --git a/src/parser.c b/src/parser.c
index 4126145..4be9d4e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -274,9 +274,10 @@ cleanup_stack()
274{ 274{
275 int delta = tos - curs; 275 int delta = tos - curs;
276 276
277 if (delta) 277 if (delta > 0)
278 memmove(token_stack, token_stack+curs, delta*sizeof(token_stack[0])); 278 memmove(token_stack, token_stack+curs, delta*sizeof(token_stack[0]));
279 279 else if (delta < 0) /* Invalid input */
280 delta = 0;
280 tos = delta; 281 tos = delta;
281 curs = 0; 282 curs = 0;
282} 283}
@@ -652,6 +653,8 @@ parse_function_declaration(Ident *ident, int parm)
652 case LBRACE: 653 case LBRACE:
653 if (ident->name) { 654 if (ident->name) {
654 caller = lookup(ident->name); 655 caller = lookup(ident->name);
656 if (caller && caller->storage == AutoStorage)
657 caller = NULL;
655 func_body(); 658 func_body();
656 } 659 }
657 break; 660 break;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5f7d77c..4173c5f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,7 @@ TESTSUITE_AT = \
48 funcarg.at\ 48 funcarg.at\
49 hiding.at\ 49 hiding.at\
50 include.at\ 50 include.at\
51 invalid.at\
51 knr.at\ 52 knr.at\
52 multi.at\ 53 multi.at\
53 nfarg.at\ 54 nfarg.at\
diff --git a/tests/invalid.at b/tests/invalid.at
new file mode 100644
index 0000000..581f8eb
--- /dev/null
+++ b/tests/invalid.at
@@ -0,0 +1,34 @@
1# This file is part of GNU cflow testsuite. -*- Autotest -*-
2# Copyright (C) 2016 Sergey Poznyakoff
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License as
6# published by the Free Software Foundation; either version 3, or (at
7# your option) any later version.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12# General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([invalid input])
18AT_KEYWORDS([invalid])
19
20# See https://savannah.gnu.org/bugs/?44113
21CFLOW_CHECK([
22m{int
23r(a(n){}e
24])
25
26CFLOW_CHECK([
27e(S,t)e(S{
28])
29
30CFLOW_CHECK([
31n{void y(r(i){}a
32])
33
34AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index e516a78..7ed3d7a 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -71,5 +71,6 @@ m4_include([struct02.at])
71m4_include([struct03.at]) 71m4_include([struct03.at])
72m4_include([struct04.at]) 72m4_include([struct04.at])
73m4_include([decl01.at]) 73m4_include([decl01.at])
74m4_include([invalid.at])
74 75
75# End of testsuite.at 76# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.