From 8c1d8b1d109fda4592084d6037c2e1870e94a6b3 Mon Sep 17 00:00:00 2001
From: Tinny Ng <tng@apache.org>
Date: Mon, 25 Feb 2002 21:18:53 +0000
Subject: [PATCH] Schema Fix: Ensure no invalid uri index for UPA checking.

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@173530 13f79535-47bb-0310-9956-ffa450edef68
---
 .../validators/common/DFAContentModel.cpp     | 12 +++++++---
 .../validators/common/MixedContentModel.hpp   | 11 ++++++---
 .../validators/common/SimpleContentModel.cpp  | 15 ++++++++----
 .../validators/schema/SchemaValidator.cpp     |  8 ++++++-
 .../schema/SubstitutionGroupComparator.cpp    | 24 +++++++++++++++----
 5 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/src/xercesc/validators/common/DFAContentModel.cpp b/src/xercesc/validators/common/DFAContentModel.cpp
index 789c9e0f2..6dd132025 100644
--- a/src/xercesc/validators/common/DFAContentModel.cpp
+++ b/src/xercesc/validators/common/DFAContentModel.cpp
@@ -56,8 +56,11 @@
 
 /*
  * $Log$
- * Revision 1.1  2002/02/01 22:22:38  peiyongz
- * Initial revision
+ * Revision 1.2  2002/02/25 21:18:53  tng
+ * Schema Fix: Ensure no invalid uri index for UPA checking.
+ *
+ * Revision 1.1.1.1  2002/02/01 22:22:38  peiyongz
+ * sane_include
  *
  * Revision 1.29  2001/12/10 21:42:55  peiyongz
  * Memory Leak: fLeafNameTypeVector
@@ -1192,7 +1195,10 @@ void DFAContentModel::checkUniqueParticleAttribution (SchemaGrammar*    const pG
 
         unsigned int orgURIIndex = fElemMap[i]->getURI();
 
-        if (orgURIIndex != XMLContentModel::gEOCFakeId) {
+        if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&
+            (orgURIIndex != XMLContentModel::gEpsilonFakeId) &&
+            (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&
+            (orgURIIndex != XMLElementDecl::fgPCDataElemId)) {
             fElemMap[i]->setURI(pContentSpecOrgURI[orgURIIndex]);
         }
     }
diff --git a/src/xercesc/validators/common/MixedContentModel.hpp b/src/xercesc/validators/common/MixedContentModel.hpp
index 186bf5efb..978d9abf8 100644
--- a/src/xercesc/validators/common/MixedContentModel.hpp
+++ b/src/xercesc/validators/common/MixedContentModel.hpp
@@ -56,8 +56,11 @@
 
 /*
  * $Log$
- * Revision 1.1  2002/02/01 22:22:39  peiyongz
- * Initial revision
+ * Revision 1.2  2002/02/25 21:18:53  tng
+ * Schema Fix: Ensure no invalid uri index for UPA checking.
+ *
+ * Revision 1.1.1.1  2002/02/01 22:22:39  peiyongz
+ * sane_include
  *
  * Revision 1.12  2001/11/28 16:46:20  tng
  * Schema fix: Check for invalid URI index first.
@@ -260,7 +263,9 @@ inline void MixedContentModel::checkUniqueParticleAttribution
     unsigned int i = 0;
     for (i = 0; i < fCount; i++) {
         unsigned int orgURIIndex = fChildren[i]->getURI();
-        if (orgURIIndex != XMLContentModel::gEOCFakeId)
+        if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&
+            (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&
+            (orgURIIndex != XMLElementDecl::fgPCDataElemId))
             fChildren[i]->setURI(pContentSpecOrgURI[orgURIIndex]);
     }
 
diff --git a/src/xercesc/validators/common/SimpleContentModel.cpp b/src/xercesc/validators/common/SimpleContentModel.cpp
index 3bbb1c31b..5038d80dd 100644
--- a/src/xercesc/validators/common/SimpleContentModel.cpp
+++ b/src/xercesc/validators/common/SimpleContentModel.cpp
@@ -56,8 +56,11 @@
 
 /*
  * $Log$
- * Revision 1.1  2002/02/01 22:22:39  peiyongz
- * Initial revision
+ * Revision 1.2  2002/02/25 21:18:53  tng
+ * Schema Fix: Ensure no invalid uri index for UPA checking.
+ *
+ * Revision 1.1.1.1  2002/02/01 22:22:39  peiyongz
+ * sane_include
  *
  * Revision 1.11  2001/11/28 16:46:20  tng
  * Schema fix: Check for invalid URI index first.
@@ -499,11 +502,15 @@ void SimpleContentModel::checkUniqueParticleAttribution
     unsigned int orgURIIndex = 0;
 
     orgURIIndex = fFirstChild->getURI();
-    if (orgURIIndex != XMLContentModel::gEOCFakeId)
+    if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&
+        (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&
+        (orgURIIndex != XMLElementDecl::fgPCDataElemId))
         fFirstChild->setURI(pContentSpecOrgURI[orgURIIndex]);
 
     orgURIIndex = fSecondChild->getURI();
-    if (orgURIIndex != XMLContentModel::gEOCFakeId)
+    if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&
+        (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&
+        (orgURIIndex != XMLElementDecl::fgPCDataElemId))
         fSecondChild->setURI(pContentSpecOrgURI[orgURIIndex]);
 
     // only possible violation is when it's a choice
diff --git a/src/xercesc/validators/schema/SchemaValidator.cpp b/src/xercesc/validators/schema/SchemaValidator.cpp
index 130ff7f9a..a4c784f5b 100644
--- a/src/xercesc/validators/schema/SchemaValidator.cpp
+++ b/src/xercesc/validators/schema/SchemaValidator.cpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2002/02/25 21:18:18  tng
+ * Schema Fix: Ensure no invalid uri index for UPA checking.
+ *
  * Revision 1.2  2002/02/07 16:41:29  knoaman
  * Fix for xsi:type.
  *
@@ -482,7 +485,10 @@ void SchemaValidator::validateElement(const   XMLElementDecl*  elemDef)
         unsigned int uri = fXsiType->getURI();
         const XMLCh* localPart = fXsiType->getLocalPart();
 
-        if (uri != XMLElementDecl::fgInvalidElemId || uri != XMLElementDecl::fgPCDataElemId) {
+        if (uri != XMLElementDecl::fgInvalidElemId ||
+            uri != XMLElementDecl::fgPCDataElemId ||
+            uri != XMLContentModel::gEpsilonFakeId ||
+            uri != XMLContentModel::gEOCFakeId) {
             // retrieve Grammar for the uri
             const XMLCh* uriStr = getScanner()->getURIText(uri);
             SchemaGrammar* sGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(uriStr);
diff --git a/src/xercesc/validators/schema/SubstitutionGroupComparator.cpp b/src/xercesc/validators/schema/SubstitutionGroupComparator.cpp
index c6d19a91d..4f9de0ba7 100644
--- a/src/xercesc/validators/schema/SubstitutionGroupComparator.cpp
+++ b/src/xercesc/validators/schema/SubstitutionGroupComparator.cpp
@@ -56,8 +56,11 @@
 
 /*
  * $Log$
- * Revision 1.1  2002/02/01 22:22:47  peiyongz
- * Initial revision
+ * Revision 1.2  2002/02/25 21:18:18  tng
+ * Schema Fix: Ensure no invalid uri index for UPA checking.
+ *
+ * Revision 1.1.1.1  2002/02/01 22:22:47  peiyongz
+ * sane_include
  *
  * Revision 1.11  2001/11/28 16:46:03  tng
  * Schema fix: Initialize the temporary string as null terminated.
@@ -124,7 +127,8 @@ bool SubstitutionGroupComparator::isEquivalentTo(QName* const anElement
     unsigned int uriId = anElement->getURI();
     if (uriId == XMLContentModel::gEOCFakeId ||
         uriId == XMLContentModel::gEpsilonFakeId ||
-        uriId == XMLElementDecl::fgPCDataElemId)
+        uriId == XMLElementDecl::fgPCDataElemId ||
+        uriId == XMLElementDecl::fgInvalidElemId)
         return false;
 
     const XMLCh* uri = fStringPool->getValueForId(uriId);
@@ -241,7 +245,12 @@ bool SubstitutionGroupComparator::isAllowedByWildcard(SchemaGrammar* const pGram
     unsigned int uriId = element->getURI();
 
     if ((!wother && uriId == wuri) ||
-        (wother && uriId != wuri && uriId != XMLContentModel::gEOCFakeId && uriId != XMLContentModel::gEpsilonFakeId))
+        (wother &&
+         uriId != wuri &&
+         uriId != XMLContentModel::gEOCFakeId &&
+         uriId != XMLContentModel::gEpsilonFakeId &&
+         uriId != XMLElementDecl::fgPCDataElemId &&
+         uriId != XMLElementDecl::fgInvalidElemId))
     {
         return true;
     }
@@ -265,7 +274,12 @@ bool SubstitutionGroupComparator::isAllowedByWildcard(SchemaGrammar* const pGram
         unsigned int subUriId = subsElements->elementAt(i)->getElementName()->getURI();
 
         if ((!wother && subUriId == wuri) ||
-            (wother && subUriId != wuri && subUriId != XMLContentModel::gEOCFakeId && subUriId != XMLContentModel::gEpsilonFakeId))
+            (wother &&
+             subUriId != wuri &&
+             subUriId != XMLContentModel::gEOCFakeId &&
+             subUriId != XMLContentModel::gEpsilonFakeId &&
+             subUriId != XMLElementDecl::fgPCDataElemId &&
+             subUriId != XMLElementDecl::fgInvalidElemId))
         {
             return true;
         }
-- 
GitLab