7195301: XML Signature DOM implementation should not use instanceof to determine type of Node
Reviewed-by: xuelei
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java Tue Sep 04 02:24:51 2012 -0700
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java Mon Sep 10 08:57:51 2012 -0400
@@ -153,8 +153,8 @@
break;
}
}
- for (Node el=config.getFirstChild();el!=null;el=el.getNextSibling()) {
- if (!(el instanceof Element)) {
+ for (Node el=config.getFirstChild();el!=null;el=el.getNextSibling()) {
+ if (el.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
String tag=el.getLocalName();
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java Tue Sep 04 02:24:51 2012 -0700
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java Mon Sep 10 08:57:51 2012 -0400
@@ -205,7 +205,7 @@
try {
NameSpaceSymbTable ns=new NameSpaceSymbTable();
int nodeLevel=NODE_BEFORE_DOCUMENT_ELEMENT;
- if (rootNode instanceof Element) {
+ if (rootNode != null && rootNode.getNodeType() == Node.ELEMENT_NODE) {
//Fills the nssymbtable with the definitions of the parent of the root subnode
getParentNameSpaces((Element)rootNode,ns);
nodeLevel=NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
@@ -335,7 +335,7 @@
return;
sibling=parentNode.getNextSibling();
parentNode=parentNode.getParentNode();
- if (!(parentNode instanceof Element)) {
+ if (parentNode !=null && parentNode.getNodeType() != Node.ELEMENT_NODE) {
documentLevel=NODE_AFTER_DOCUMENT_ELEMENT;
parentNode=null;
}
@@ -391,7 +391,7 @@
return;
boolean currentNodeIsVisible = false;
NameSpaceSymbTable ns=new NameSpaceSymbTable();
- if (currentNode instanceof Element)
+ if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE)
getParentNameSpaces((Element)currentNode,ns);
Node sibling=null;
Node parentNode=null;
@@ -512,7 +512,7 @@
return;
sibling=parentNode.getNextSibling();
parentNode=parentNode.getParentNode();
- if (!(parentNode instanceof Element)) {
+ if (parentNode != null && parentNode.getNodeType() != Node.ELEMENT_NODE) {
parentNode=null;
documentLevel=NODE_AFTER_DOCUMENT_ELEMENT;
}
@@ -594,18 +594,14 @@
final void getParentNameSpaces(Element el,NameSpaceSymbTable ns) {
List<Element> parents=new ArrayList<Element>(10);
Node n1=el.getParentNode();
- if (!(n1 instanceof Element)) {
+ if (n1 == null || n1.getNodeType() != Node.ELEMENT_NODE) {
return;
}
//Obtain all the parents of the elemnt
- Element parent=(Element) n1;
- while (parent!=null) {
- parents.add(parent);
- Node n=parent.getParentNode();
- if (!(n instanceof Element )) {
- break;
- }
- parent=(Element)n;
+ Node parent = n1;
+ while (parent!=null && parent.getNodeType() == Node.ELEMENT_NODE) {
+ parents.add((Element)parent);
+ parent = parent.getParentNode();
}
//Visit them in reverse order.
ListIterator<Element> it=parents.listIterator(parents.size());
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java Tue Sep 04 02:24:51 2012 -0700
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java Mon Sep 10 08:57:51 2012 -0400
@@ -1445,7 +1445,7 @@
// The de-serialiser returns a fragment whose children we need to
// take on.
- if (sourceParent instanceof Document) {
+ if (sourceParent != null && sourceParent.getNodeType() == Node.DOCUMENT_NODE) {
// If this is a content decryption, this may have problems
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/RetrievalMethodResolver.java Tue Sep 04 02:24:51 2012 -0700
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/RetrievalMethodResolver.java Mon Sep 10 08:57:51 2012 -0400
@@ -283,7 +283,7 @@
Element e=null;
while (it.hasNext()) {
Node currentNode=it.next();
- if (currentNode instanceof Element) {
+ if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE) {
e=(Element)currentNode;
break;
}
@@ -292,14 +292,14 @@
List<Element> parents=new ArrayList<Element>(10);
//Obtain all the parents of the elemnt
- do {
+ while (e != null) {
parents.add(e);
Node n=e.getParentNode();
- if (!(n instanceof Element )) {
+ if (n == null || n.getNodeType() != Node.ELEMENT_NODE) {
break;
}
e=(Element)n;
- } while (e!=null);
+ }
//Visit them in reverse order.
ListIterator<Element> it2=parents.listIterator(parents.size()-1);
Element ele=null;
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java Tue Sep 04 02:24:51 2012 -0700
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java Mon Sep 10 08:57:51 2012 -0400
@@ -225,7 +225,7 @@
} while (sibling==null && parentNode!=null) {
sibling=parentNode.getNextSibling();
parentNode=parentNode.getParentNode();
- if (!(parentNode instanceof Element)) {
+ if (parentNode != null && parentNode.getNodeType() != Node.ELEMENT_NODE) {
parentNode=null;
}
}