[cpp-xmltooling] 01/02: Guard XMLDateTime calls.

Scott Cantor cantor.2 at osu.edu
Thu Dec 13 18:33:55 EST 2018


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch master
in repository cpp-xmltooling.

View the commit online:
http://git.shibboleth.net/view/?p=cpp-xmltooling.git;a=commit;h=b6f372e41605d9afec8d755e420f8277e37f4185

commit b6f372e41605d9afec8d755e420f8277e37f4185
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Dec 13 18:33:01 2018 -0500

    Guard XMLDateTime calls.
---
 xmltooling/AbstractXMLObject.cpp | 71 +++++++++++++++++++++++++++++++---------
 1 file changed, 56 insertions(+), 15 deletions(-)

diff --git a/xmltooling/AbstractXMLObject.cpp b/xmltooling/AbstractXMLObject.cpp
index b974b1f..006518a 100644
--- a/xmltooling/AbstractXMLObject.cpp
+++ b/xmltooling/AbstractXMLObject.cpp
@@ -35,6 +35,7 @@ using std::set;
 
 using xercesc::XMLString;
 using xercesc::XMLDateTime;
+using xercesc::XMLException;
 
 XMLObject::XMLObject()
 {
@@ -244,39 +245,79 @@ XMLDateTime* AbstractXMLObject::prepareForAssignment(XMLDateTime* oldValue, cons
     if (!oldValue) {
         if (newValue) {
             releaseThisandParentDOM();
-            return new XMLDateTime(*newValue);
+            try {
+                return new XMLDateTime(*newValue);
+            }
+            catch (const XMLException& e) {
+                auto_ptr_char temp(e.getMessage());
+                throw XMLObjectException(temp.get() ? temp.get() : "XMLException duplicating XMLDateTime object");
+            }
         }
         return nullptr;
     }
 
-    delete oldValue;
     releaseThisandParentDOM();
-    return newValue ? new XMLDateTime(*newValue) : nullptr;
+
+    // Avoid deleting existing object until new one is safely created.
+    XMLDateTime* ret = nullptr;
+    try {
+        if (newValue)
+            ret = new XMLDateTime(*newValue);
+    }
+    catch (const XMLException& e) {
+        auto_ptr_char temp(e.getMessage());
+        throw XMLObjectException(temp.get() ? temp.get() : "XMLException duplicating XMLDateTime object");
+    }
+
+    delete oldValue;
+    return ret;
 }
 
 XMLDateTime* AbstractXMLObject::prepareForAssignment(XMLDateTime* oldValue, time_t newValue, bool duration)
 {
+    // Avoid deleting existing object until new one is safely created.
+    XMLDateTime* ret = nullptr;
+    try {
+        ret = new XMLDateTime(newValue, duration);
+        if (duration)
+            ret->parseDuration();
+        else
+            ret->parseDateTime();
+    }
+    catch (const XMLException& e) {
+        auto_ptr_char temp(e.getMessage());
+        throw XMLObjectException(temp.get() ? temp.get() : "XMLException creating XMLDateTime object");
+    }
+
     delete oldValue;
     releaseThisandParentDOM();
-    XMLDateTime* ret = new XMLDateTime(newValue, duration);
-    if (duration)
-        ret->parseDuration();
-    else
-        ret->parseDateTime();
     return ret;
 }
 
 XMLDateTime* AbstractXMLObject::prepareForAssignment(XMLDateTime* oldValue, const XMLCh* newValue, bool duration)
 {
+    if (!newValue || !*newValue) {
+        delete oldValue;
+        releaseThisandParentDOM();
+        return nullptr;
+    }
+
+    // Avoid deleting existing object until new one is safely created.
+    XMLDateTime* ret = nullptr;
+    try {
+        ret = new XMLDateTime(newValue);
+        if (duration)
+            ret->parseDuration();
+        else
+            ret->parseDateTime();
+    }
+    catch (const XMLException& e) {
+        auto_ptr_char temp(e.getMessage());
+        throw XMLObjectException(temp.get() ? temp.get() : "XMLException creating XMLDateTime object");
+    }
+
     delete oldValue;
     releaseThisandParentDOM();
-    if (!newValue || !*newValue)
-        return nullptr;
-    XMLDateTime* ret = new XMLDateTime(newValue);
-    if (duration)
-        ret->parseDuration();
-    else
-        ret->parseDateTime();
     return ret;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list