Prevent reference XML reader segfault on nullptr error strings
authorAleksei Iupinov <a.yupinov@gmail.com>
Wed, 6 Sep 2017 15:18:44 +0000 (17:18 +0200)
committerAleksei Iupinov <a.yupinov@gmail.com>
Tue, 12 Sep 2017 10:00:28 +0000 (12:00 +0200)
It is possible for TinyXML2 to return null pointers to the error strings.
This could cause XML reference data reader to segfault.

Refs #2241

Change-Id: I8b72917785080023f75388281dd2cbb4f30da925

src/testutils/refdata-xml.cpp

index bdf6018cd81bced5ff944aa8892ec9a59e20e1ae..0b7a8269444dcf20a678865e51196d1cff54fd33 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -208,9 +208,21 @@ readReferenceDataFile(const std::string &path)
     document.LoadFile(path.c_str());
     if (document.Error())
     {
+        const char *errorStr1 = document.GetErrorStr1();
+        const char *errorStr2 = document.GetErrorStr2();
         std::string errorString("Error was ");
-        errorString += document.GetErrorStr1();
-        errorString += document.GetErrorStr2();
+        if (errorStr1)
+        {
+            errorString += errorStr1;
+        }
+        if (errorStr2)
+        {
+            errorString += errorStr2;
+        }
+        if (!errorStr1 && !errorStr2)
+        {
+            errorString += "not specified.";
+        }
         GMX_THROW(TestException("Reference data not parsed successfully: " + path + "\n." + errorString + "\n"));
     }
     XMLElementPtr rootNode = document.RootElement();