Revision: 14540
          http://gate.svn.sourceforge.net/gate/?rev=14540&view=rev
Author:   ian_roberts
Date:     2011-11-14 16:13:10 +0000 (Mon, 14 Nov 2011)
Log Message:
-----------
Fixed infinite loop in the JAPE parser if you forget to close a Java block.

Modified Paths:
--------------
    gate/trunk/src/gate/jape/parser/ParseCpsl.java
    gate/trunk/src/gate/jape/parser/ParseCpsl.jj

Modified: gate/trunk/src/gate/jape/parser/ParseCpsl.java
===================================================================
--- gate/trunk/src/gate/jape/parser/ParseCpsl.java      2011-11-14 16:00:07 UTC 
(rev 14539)
+++ gate/trunk/src/gate/jape/parser/ParseCpsl.java      2011-11-14 16:13:10 UTC 
(rev 14540)
@@ -1666,12 +1666,16 @@
   }
   }
 
-  String ConsumeBlock() throws ParseException {
+  String ConsumeBlock() throws ParseException, ParseException {
   StringBuffer block = new StringBuffer(); // to collect the block in
   int nesting = 1; // the first "{" was consumed before we were called
 
   // this is the first 'proper' token in the block
   Token nextTok = getNextToken();
+  if(nextTok.kind == EOF) {
+    throw new ParseException(errorMsgPrefix(nextTok)
+            + "Unexpected EOF in Java block");
+  }
 
   // for line numbers in the original Jape we want the first
   // token, normal or special (i.e. comments) so look back from
@@ -1717,7 +1721,13 @@
 
         // if we haven't worked all the way out of the nesting
         // then get the next token
-        if (nesting != 0) nextTok = getNextToken();
+        if (nesting != 0) {
+          nextTok = getNextToken();
+          if(nextTok.kind == EOF) {
+            throw new ParseException(errorMsgPrefix(nextTok)
+                    + "Unexpected EOF in Java block");
+          }
+        }
 
   } // while
 

Modified: gate/trunk/src/gate/jape/parser/ParseCpsl.jj
===================================================================
--- gate/trunk/src/gate/jape/parser/ParseCpsl.jj        2011-11-14 16:00:07 UTC 
(rev 14539)
+++ gate/trunk/src/gate/jape/parser/ParseCpsl.jj        2011-11-14 16:13:10 UTC 
(rev 14540)
@@ -1617,13 +1617,17 @@
 
 
 JAVACODE
-String ConsumeBlock() {
+String ConsumeBlock() throws ParseException {
   StringBuffer block = new StringBuffer(); // to collect the block in
   int nesting = 1; // the first "{" was consumed before we were called
 
   // this is the first 'proper' token in the block
   Token nextTok = getNextToken();
-
+  if(nextTok.kind == EOF) {
+    throw new ParseException(errorMsgPrefix(nextTok)
+            + "Unexpected EOF in Java block");
+  }
+  
   // for line numbers in the original Jape we want the first
   // token, normal or special (i.e. comments) so look back from
   // the first 'proper' token until we get back to the token
@@ -1668,7 +1672,13 @@
              
        // if we haven't worked all the way out of the nesting
        // then get the next token
-       if (nesting != 0) nextTok = getNextToken();
+       if (nesting != 0) {
+         nextTok = getNextToken();
+         if(nextTok.kind == EOF) {
+           throw new ParseException(errorMsgPrefix(nextTok)
+                   + "Unexpected EOF in Java block");
+         }
+       }
 
   } // while
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to