diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-03-22 13:11:14 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-03-22 13:16:24 +0200 |
commit | 03b7314673fc4030e933f86890aad7f82ec30eca (patch) | |
tree | 0e9e00ce9cfc5a52a2ff21c06f800b7b9879a22a | |
parent | f91b19e696794204f2ba05587eb0dc0475c65345 (diff) | |
download | cflow-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-- | .gitignore | 1 | ||||
-rw-r--r-- | src/parser.c | 7 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/invalid.at | 34 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
5 files changed, 42 insertions, 2 deletions
@@ -13,6 +13,7 @@ | |||
13 | ABOUT-NLS | 13 | ABOUT-NLS |
14 | ChangeLog | 14 | ChangeLog |
15 | INSTALL | 15 | INSTALL |
16 | TAGS | ||
16 | Makefile | 17 | Makefile |
17 | Makefile.in | 18 | Makefile.in |
18 | aclocal.m4 | 19 | aclocal.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 | |||
17 | AT_SETUP([invalid input]) | ||
18 | AT_KEYWORDS([invalid]) | ||
19 | |||
20 | # See https://savannah.gnu.org/bugs/?44113 | ||
21 | CFLOW_CHECK([ | ||
22 | m{int | ||
23 | r(a(n){}e | ||
24 | ]) | ||
25 | |||
26 | CFLOW_CHECK([ | ||
27 | e(S,t)e(S{ | ||
28 | ]) | ||
29 | |||
30 | CFLOW_CHECK([ | ||
31 | n{void y(r(i){}a | ||
32 | ]) | ||
33 | |||
34 | AT_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]) | |||
71 | m4_include([struct03.at]) | 71 | m4_include([struct03.at]) |
72 | m4_include([struct04.at]) | 72 | m4_include([struct04.at]) |
73 | m4_include([decl01.at]) | 73 | m4_include([decl01.at]) |
74 | m4_include([invalid.at]) | ||
74 | 75 | ||
75 | # End of testsuite.at | 76 | # End of testsuite.at |