writefrudata: Fix verifyFruData to skip CRC check for internal use area.

The contents of the internal use area are not defined beyond the first
byte, which means that we should not expect its last byte to be a CRC
for the area.

Change-Id: I15aba7f48e13f8a93c5a6b7e3262d9227da5dad7
Signed-off-by: Oskar Senft <osk@google.com>
diff --git a/writefrudata.cpp b/writefrudata.cpp
index 114e4e9..dbf96cb 100644
--- a/writefrudata.cpp
+++ b/writefrudata.cpp
@@ -360,13 +360,14 @@
 }
 
 /**
- * Validates the data for CRC and mandatory fields.
+ * Validates the data for mandatory fields and CRC if selected.
  *
  * @param[in] data - the data to verify
  * @param[in] len - the length of the region to verify
+ * @param[in] validateCrc - whether to validate the CRC
  * @return non-zero on failure
  */
-int verifyFruData(const uint8_t* data, const size_t len)
+int verifyFruData(const uint8_t* data, const size_t len, bool validateCrc)
 {
     uint8_t checksum = 0;
     int rc = -1;
@@ -386,6 +387,12 @@
     }
 #endif
 
+    if (!validateCrc)
+    {
+        // There's nothing else to do for this area.
+        return EXIT_SUCCESS;
+    }
+
     // See if the calculated CRC matches with the embedded one.
     // CRC to be calculated on all except the last one that is CRC itself.
     checksum = calculateCRC(data, len - 1);
@@ -484,8 +491,11 @@
             // Save off the data.
             std::memcpy(areaData, &((uint8_t*)fruData)[areaOffset], areaLen);
 
-            // Validate the crc
-            rc = verifyFruData(areaData, areaLen);
+            // Validate the CRC, but not for the internal use area, since its
+            // contents beyond the first byte are not defined in the spec and
+            // it may not end with a CRC byte.
+            bool validateCrc = fruEntry != IPMI_FRU_INTERNAL_OFFSET;
+            rc = verifyFruData(areaData, areaLen, validateCrc);
             if (rc < 0)
             {
                 log<level::ERR>("Err validating FRU area",
@@ -494,7 +504,7 @@
             }
             else
             {
-                log<level::DEBUG>("Successfully verified area checksum.",
+                log<level::DEBUG>("Successfully verified area.",
                                   entry("OFFSET=%d", areaOffset));
             }
 
@@ -543,7 +553,7 @@
     }
 
     // Verify the CRC and size
-    rc = verifyFruData(commonHdr, sizeof(commonHdr));
+    rc = verifyFruData(commonHdr, sizeof(commonHdr), true);
     if (rc < 0)
     {
         log<level::ERR>("Failed to validate common header");