Skip to content

Commit 79774c6

Browse files
committed
Missed a couple possibly unsafe XMLUtils
1 parent 6b32b3c commit 79774c6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/edu/stanford/nlp/ie/machinereading/common/DomReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.w3c.dom.NodeList;
1717
import org.xml.sax.SAXException;
1818

19+
import edu.stanford.nlp.util.XMLUtils;
20+
1921
/**
2022
* Generic DOM reader for an XML file
2123
*/
@@ -127,7 +129,7 @@ public static String getAttributeValue(Node node, String attributeName) {
127129
public static Document readDocument(File f) throws IOException, SAXException, ParserConfigurationException {
128130
Document document = null;
129131

130-
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
132+
DocumentBuilderFactory factory = XMLUtils.safeDocumentBuilderFactory();
131133
// factory.setValidating(true);
132134
// factory.setNamespaceAware(true);
133135

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import edu.stanford.nlp.semgraph.semgrex.ssurgeon.pred.*;
2828
import edu.stanford.nlp.semgraph.semgrex.SemgrexPattern;
2929
import edu.stanford.nlp.util.Generics;
30+
import edu.stanford.nlp.util.XMLUtils;
3031
import edu.stanford.nlp.util.logging.Redwood;
3132

3233

@@ -397,7 +398,7 @@ public static String writeToString(SsurgeonPattern pattern) {
397398

398399
private static Document createPatternXMLDoc(List<SsurgeonPattern> patterns) {
399400
try {
400-
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
401+
DocumentBuilderFactory dbf = XMLUtils.safeDocumentBuilderFactory();
401402
DocumentBuilder db = dbf.newDocumentBuilder();
402403
Document domDoc = db.newDocument();
403404
Element rootElt = domDoc.createElement(SsurgeonPattern.ELT_LIST_TAG);
@@ -452,7 +453,7 @@ private static Document createPatternXMLDoc(List<SsurgeonPattern> patterns) {
452453
@SuppressWarnings("unchecked")
453454
public List<SsurgeonPattern> readFromFile(File file) throws Exception {
454455
List<SsurgeonPattern> retList = new ArrayList<>();
455-
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
456+
Document doc = XMLUtils.safeDocumentBuilderFactory().newDocumentBuilder().parse(file);
456457

457458
if (VERBOSE)
458459
System.out.println("Reading ssurgeon file="+file.getAbsolutePath());

0 commit comments

Comments
 (0)