summaryrefslogtreecommitdiffstats
path: root/parse.cxx
diff options
context:
space:
mode:
authorWenji Huang <wenji.huang@oracle.com>2010-01-12 13:45:55 +0800
committerWenji Huang <wenji.huang@oracle.com>2010-01-12 13:45:55 +0800
commitc28668eaddf956b8c481e436e939d0b35bacaf68 (patch)
treea7cd9ebe06e19b1478172236f839000ddd602089 /parse.cxx
parentf2aadddae0d01fa5a676404e49c6c36825b40512 (diff)
downloadsystemtap-steved-c28668eaddf956b8c481e436e939d0b35bacaf68.tar.gz
systemtap-steved-c28668eaddf956b8c481e436e939d0b35bacaf68.tar.xz
systemtap-steved-c28668eaddf956b8c481e436e939d0b35bacaf68.zip
PR10747: check invalid preprocessor construct
* parse.cxx (scan_pp): Match '%(' and '%?'. * testsuite/semko/conditional.stp: New test.
Diffstat (limited to 'parse.cxx')
-rw-r--r--parse.cxx20
1 files changed, 18 insertions, 2 deletions
diff --git a/parse.cxx b/parse.cxx
index 55ec53fb..edb19275 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -380,6 +380,7 @@ parser::scan_pp (bool wildcard)
vector<const token*> my_enqueued_pp;
int nesting = 0;
+ int then = 0;
while (true) // consume THEN tokens
{
try
@@ -394,11 +395,18 @@ parser::scan_pp (bool wildcard)
if (m && m->type == tok_operator && m->content == "%(") // nested %(
nesting ++;
+ if (m && m->type == tok_operator && m->content == "%?") {
+ then ++;
+ if (nesting != then)
+ throw parse_error ("incomplete conditional - missing '%('", m);
+ }
if (nesting == 0 && m && (m->type == tok_operator && (m->content == "%:" || // ELSE
m->content == "%)"))) // END
break;
- if (nesting && m && m->type == tok_operator && m->content == "%)") // nested %)
+ if (nesting && m && m->type == tok_operator && m->content == "%)") { // nested %)
nesting --;
+ then --;
+ }
if (!m)
throw parse_error ("incomplete conditional - missing '%:' or '%)'", t);
@@ -414,6 +422,7 @@ parser::scan_pp (bool wildcard)
{
delete m; // "%:"
int nesting = 0;
+ int then = 0;
while (true)
{
try
@@ -428,10 +437,17 @@ parser::scan_pp (bool wildcard)
if (m && m->type == tok_operator && m->content == "%(") // nested %(
nesting ++;
+ if (m && m->type == tok_operator && m->content == "%?") {
+ then ++;
+ if (nesting != then)
+ throw parse_error ("incomplete conditional - missing '%('", m);
+ }
if (nesting == 0 && m && m->type == tok_operator && m->content == "%)") // END
break;
- if (nesting && m && m->type == tok_operator && m->content == "%)") // nested %)
+ if (nesting && m && m->type == tok_operator && m->content == "%)") { // nested %)
nesting --;
+ then --;
+ }
if (!m)
throw parse_error ("incomplete conditional - missing %)", t);