[Uml-devel] kdesdk/umbrello/umbrello/classparser

Oliver Kellogg okellogg at users.sourceforge.net
Wed Dec 15 16:47:02 UTC 2004


CVS commit by okellogg: 

Guard against stack overflow of m_currentNamespace and m_currentClass


  M +15 -3     cpptree2uml.cpp   1.15
  M +3 -2      cpptree2uml.h   1.7


--- kdesdk/umbrello/umbrello/classparser/cpptree2uml.cpp  #1.14:1.15
@@ -79,5 +79,9 @@ void CppTree2Uml::parseNamespace( Namesp
     UMLPackage *ns = (UMLPackage *)o;
     m_currentScope.push_back( nsName );
-    m_currentNamespace[++m_nsCnt] = ns;
+    if (++m_nsCnt > STACKSIZE) {
+        kdError() << "CppTree2Uml::parseNamespace: excessive namespace nesting" << endl;
+        m_nsCnt = STACKSIZE;
+    }
+    m_currentNamespace[m_nsCnt] = ns;
 
     TreeParser::parseNamespace( ast );
@@ -299,6 +303,14 @@ void CppTree2Uml::parseClassSpecifier( C
 
     m_currentScope.push_back( className );
-    m_currentClass[++m_clsCnt] = klass;
-    m_currentNamespace[++m_nsCnt] = (UMLPackage*)klass;
+    if (++m_clsCnt > STACKSIZE) {
+        kdError() << "CppTree2Uml::parseNamespace: excessive class nesting" << endl;
+        m_clsCnt = STACKSIZE;
+    }
+    m_currentClass[m_clsCnt] = klass;
+    if (++m_nsCnt > STACKSIZE) {
+        kdError() << "CppTree2Uml::parseNamespace: excessive namespace nesting" << endl;
+        m_nsCnt = STACKSIZE;
+    }
+    m_currentNamespace[m_nsCnt] = (UMLPackage*)klass;
 
     TreeParser::parseClassSpecifier( ast );

--- kdesdk/umbrello/umbrello/classparser/cpptree2uml.h  #1.6:1.7
@@ -82,6 +82,7 @@ private:
 
     DeclaratorAST* m_currentDeclarator;
-    UMLPackage* m_currentNamespace[32];  ///< stack
-    UMLClass* m_currentClass[32];  ///< stack
+#   define STACKSIZE 30
+    UMLPackage* m_currentNamespace[STACKSIZE+1];  ///< stack
+    UMLClass* m_currentClass[STACKSIZE+1];  ///< stack
     int m_nsCnt;  ///< stack top for m_currentNamespace
     int m_clsCnt;  ///< stack top for m_currentClass






More information about the umbrello-devel mailing list