PEL: Check UserData section size before adding

While not really likely, it is technically possible that the
AdditionalData property in an event log is large enough that saving it
into a UserData section could make the PEL exceed its maximum size of
16KB.  To guard against this, check that an overflow wouldn't occur
before saving that section in the PEL.

In future commits, other UserData sections will be added where this
check will also be needed.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Iac312a24b1d445e93de5a09f35a43d940571a3f8
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index d1c9620..6d3f010 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -59,7 +59,12 @@
     if (!additionalData.empty())
     {
         auto ud = util::makeADUserDataSection(additionalData);
-        _optionalSections.push_back(std::move(ud));
+
+        // To be safe, check there isn't too much data
+        if (size() + ud->header().size <= _maxPELSize)
+        {
+            _optionalSections.push_back(std::move(ud));
+        }
     }
 
     _ph->setSectionCount(2 + _optionalSections.size());
diff --git a/extensions/openpower-pels/pel.hpp b/extensions/openpower-pels/pel.hpp
index c3c9f5a..24e5e56 100644
--- a/extensions/openpower-pels/pel.hpp
+++ b/extensions/openpower-pels/pel.hpp
@@ -324,6 +324,11 @@
      */
     void printSectionInJSON(const Section& section, std::string& buf,
                             std::map<uint16_t, size_t>& pluralSections) const;
+
+    /**
+     * @brief The maximum size a PEL can be in bytes.
+     */
+    static constexpr size_t _maxPELSize = 16384;
 };
 
 namespace util