diff --git a/java/src/org/apache/xml/resolver/CatalogException.java b/java/src/org/apache/xml/resolver/CatalogException.java index 9bd6d8f..3baddc2 100644 --- a/java/src/org/apache/xml/resolver/CatalogException.java +++ b/java/src/org/apache/xml/resolver/CatalogException.java @@ -84,6 +84,8 @@ public class CatalogException extends Exception { public static final int UNPARSEABLE = 6; /** XML but parse failed */ public static final int PARSE_FAILED = 7; + /** Text catalog ended in mid-comment */ + public static final int UNENDED_COMMENT = 8; /** * The embedded exception if tunnelling, or null. diff --git a/java/src/org/apache/xml/resolver/readers/TR9401CatalogReader.java b/java/src/org/apache/xml/resolver/readers/TR9401CatalogReader.java index bbe1bc2..f6008e8 100644 --- a/java/src/org/apache/xml/resolver/readers/TR9401CatalogReader.java +++ b/java/src/org/apache/xml/resolver/readers/TR9401CatalogReader.java @@ -113,56 +113,65 @@ public class TR9401CatalogReader extends TextCatalogReader { Vector unknownEntry = null; - while (true) { - String token = nextToken(); + try { + while (true) { + String token = nextToken(); - if (token == null) { - if (unknownEntry != null) { - catalog.unknownEntry(unknownEntry); - unknownEntry = null; - } - catfile.close(); - catfile = null; - return; - } - - String entryToken = null; - if (caseSensitive) { - entryToken = token; - } else { - entryToken = token.toUpperCase(); - } - - if (entryToken.equals("DELEGATE")) { - entryToken = "DELEGATE_PUBLIC"; - } - - try { - int type = CatalogEntry.getEntryType(entryToken); - int numArgs = CatalogEntry.getEntryArgCount(type); - Vector args = new Vector(); - - if (unknownEntry != null) { - catalog.unknownEntry(unknownEntry); - unknownEntry = null; - } - - for (int count = 0; count < numArgs; count++) { - args.addElement(nextToken()); - } - - catalog.addEntry(new CatalogEntry(entryToken, args)); - } catch (CatalogException cex) { - if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { - if (unknownEntry == null) { - unknownEntry = new Vector(); + if (token == null) { + if (unknownEntry != null) { + catalog.unknownEntry(unknownEntry); + unknownEntry = null; } - unknownEntry.addElement(token); - } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { - catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token); - unknownEntry = null; + catfile.close(); + catfile = null; + return; } + + String entryToken = null; + if (caseSensitive) { + entryToken = token; + } else { + entryToken = token.toUpperCase(); + } + + if (entryToken.equals("DELEGATE")) { + entryToken = "DELEGATE_PUBLIC"; + } + + try { + int type = CatalogEntry.getEntryType(entryToken); + int numArgs = CatalogEntry.getEntryArgCount(type); + Vector args = new Vector(); + + if (unknownEntry != null) { + catalog.unknownEntry(unknownEntry); + unknownEntry = null; + } + + for (int count = 0; count < numArgs; count++) { + args.addElement(nextToken()); + } + + catalog.addEntry(new CatalogEntry(entryToken, args)); + } catch (CatalogException cex) { + if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { + if (unknownEntry == null) { + unknownEntry = new Vector(); + } + unknownEntry.addElement(token); + } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { + catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token); + unknownEntry = null; + } else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) { + catalog.getCatalogManager().debug.message(1, cex.getMessage()); + } + } + } + } catch (CatalogException cex2) { + if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) { + catalog.getCatalogManager().debug.message(1, cex2.getMessage()); } } + } } diff --git a/java/src/org/apache/xml/resolver/readers/TextCatalogReader.java b/java/src/org/apache/xml/resolver/readers/TextCatalogReader.java index 96f7876..25aa59e 100644 --- a/java/src/org/apache/xml/resolver/readers/TextCatalogReader.java +++ b/java/src/org/apache/xml/resolver/readers/TextCatalogReader.java @@ -156,51 +156,59 @@ public class TextCatalogReader implements CatalogReader { Vector unknownEntry = null; - while (true) { - String token = nextToken(); + try { + while (true) { + String token = nextToken(); - if (token == null) { - if (unknownEntry != null) { - catalog.unknownEntry(unknownEntry); - unknownEntry = null; - } - catfile.close(); - catfile = null; - return; - } - - String entryToken = null; - if (caseSensitive) { - entryToken = token; - } else { - entryToken = token.toUpperCase(); - } - - try { - int type = CatalogEntry.getEntryType(entryToken); - int numArgs = CatalogEntry.getEntryArgCount(type); - Vector args = new Vector(); - - if (unknownEntry != null) { - catalog.unknownEntry(unknownEntry); - unknownEntry = null; - } - - for (int count = 0; count < numArgs; count++) { - args.addElement(nextToken()); - } - - catalog.addEntry(new CatalogEntry(entryToken, args)); - } catch (CatalogException cex) { - if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { - if (unknownEntry == null) { - unknownEntry = new Vector(); + if (token == null) { + if (unknownEntry != null) { + catalog.unknownEntry(unknownEntry); + unknownEntry = null; } - unknownEntry.addElement(token); - } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { - catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token); - unknownEntry = null; + catfile.close(); + catfile = null; + return; } + + String entryToken = null; + if (caseSensitive) { + entryToken = token; + } else { + entryToken = token.toUpperCase(); + } + + try { + int type = CatalogEntry.getEntryType(entryToken); + int numArgs = CatalogEntry.getEntryArgCount(type); + Vector args = new Vector(); + + if (unknownEntry != null) { + catalog.unknownEntry(unknownEntry); + unknownEntry = null; + } + + for (int count = 0; count < numArgs; count++) { + args.addElement(nextToken()); + } + + catalog.addEntry(new CatalogEntry(entryToken, args)); + } catch (CatalogException cex) { + if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { + if (unknownEntry == null) { + unknownEntry = new Vector(); + } + unknownEntry.addElement(token); + } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { + catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token); + unknownEntry = null; + } else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) { + catalog.getCatalogManager().debug.message(1, cex.getMessage()); + } + } + } + } catch (CatalogException cex2) { + if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) { + catalog.getCatalogManager().debug.message(1, cex2.getMessage()); } } } @@ -226,10 +234,13 @@ public class TextCatalogReader implements CatalogReader { /** * Return the next token in the catalog file. * + *
FYI: This code does not throw any sort of exception for + * a file that contains an n + * * @return The Catalog file token from the input stream. * @throws IOException If an error occurs reading from the stream. */ - protected String nextToken() throws IOException { + protected String nextToken() throws IOException, CatalogException { String token = ""; int ch, nextch; @@ -258,11 +269,16 @@ public class TextCatalogReader implements CatalogReader { // we've found a comment, skip it... ch = ' '; nextch = nextChar(); - while (ch != '-' || nextch != '-') { + while ((ch != '-' || nextch != '-') && nextch > 0) { ch = nextch; nextch = nextChar(); } + if (nextch < 0) { + throw new CatalogException(CatalogException.UNENDED_COMMENT, + "Unterminated comment in catalog file; EOF treated as end-of-comment."); + } + // Ok, we've found the end of the comment, // loop back to the top and start again... } else {