Return error when SDR offset is out of range

When reading SDRs, if the requested offset is beyond the end of the SDR,
we should return an error indicating that the offset is out of range.

Tested:
Confirmed that reading offset 0x40 or 0x41 of a 64-byte SDR return an
error:
ipmitool raw 0xa 0x23 0x01 0x00 0x87 0x00 0x40 0x1
Unable to send RAW command (channel=0x0 netfn=0xa lun=0x0 cmd=0x23 rsp=0xc9): Parameter out of range
ipmitool raw 0xa 0x23 0x01 0x00 0x87 0x00 0x41 0x1
Unable to send RAW command (channel=0x0 netfn=0xa lun=0x0 cmd=0x23 rsp=0xc9): Parameter out of range

Change-Id: I3423dddadeb3d2a5e2075ae079d263503ac0679e
Signed-off-by: Jason M. Bills <jason.m.bills@intel.com>
diff --git a/src/sensorcommands.cpp b/src/sensorcommands.cpp
index 41a6297..4dc170f 100644
--- a/src/sensorcommands.cpp
+++ b/src/sensorcommands.cpp
@@ -1794,6 +1794,12 @@
 
     size_t sdrLength = sizeof(get_sdr::SensorDataRecordHeader) +
                        hdr->record_length;
+    if (offset >= sdrLength)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "ipmiStorageGetSDR: offset is outside the record");
+        return ipmi::responseParmOutOfRange();
+    }
     if (sdrLength < (offset + bytesToRead))
     {
         bytesToRead = sdrLength - offset;