FruDevice: Enforce FRU layout order

As per Section 17 of FRU specification, FRU information areas are
required to be in order in FRU data layout which means all offset
value should be in increasing order or can be 0 if that area is
not present. Verifying these Fru layout order in early header
parsing.

Signed-off-by: Vijay Khemka <vijaykhemkalinux@gmail.com>
Change-Id: I612297df73ad3661074f16b2b6c1551dd4b055b6
diff --git a/src/FruUtils.cpp b/src/FruUtils.cpp
index ed8ab5a..4d8354c 100644
--- a/src/FruUtils.cpp
+++ b/src/FruUtils.cpp
@@ -122,6 +122,7 @@
 
     bool hasMultiRecords = false;
     size_t fruLength = fruBlockSize; // At least FRU header is present
+    unsigned int prevOffset = 0;
     for (fruAreas area = fruAreas::fruAreaInternal;
          area <= fruAreas::fruAreaMultirecord; ++area)
     {
@@ -132,6 +133,19 @@
             continue;
         }
 
+        /* Check for offset order, as per Section 17 of FRU specification, FRU
+         * information areas are required to be in order in FRU data layout
+         * which means all offset value should be in increasing order or can be
+         * 0 if that area is not present
+         */
+        if (areaOffset <= prevOffset)
+        {
+            std::cerr << "Fru area offsets are not in required order as per "
+                         "Section 17 of Fru specification\n";
+            return {};
+        }
+        prevOffset = areaOffset;
+
         // MultiRecords are different. area is not tracking section, it's
         // walking the common header.
         if (area == fruAreas::fruAreaMultirecord)